Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
mbt
Aug 13, 2012

Sad Panda posted:

I've played with MSS before, but have gone back to using PyAutoGUI with OpenCV as a backend. The jump from the Python backend to the OpenCV backend is crazy.

One of the things that I use the most is pyautogui.locateCenterOnScreen(). I flicked through the MSS API but don't see an equivalent. How would I use that if I switch to MSS?

https://docs.opencv.org/2.4/modules/imgproc/doc/object_detection.html
cv2.matchTemplate(image, templ, method[, result]) → result

mss is just a faster and easier way of getting images, you'll still need opencv for most analysis. and yeah it's ridiculous how much faster opencv is over a pure python solution

Adbot
ADBOT LOVES YOU

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
In all of the examples they do...

Python code:
for filename in screenshotter.save():
    print(filename)
What's the point of that print? The .save() creates a generator but is stubbornly refusing to give me a file and I'm going slightly loopy.

Python code:
mss.mss().save(output='monkeys.png')
This runs but outputs nothing. If I do the filename jazz it creates a generator and printing gives me useful things like..

<generator object MSSMixin.save at 0x0000020451EFBD68>

mbt
Aug 13, 2012

Sad Panda posted:

In all of the examples they do...

Python code:
for filename in screenshotter.save():
    print(filename)
What's the point of that print? The .save() creates a generator but is stubbornly refusing to give me a file and I'm going slightly loopy.

Python code:
mss.mss().save(output='monkeys.png')
This runs but outputs nothing. If I do the filename jazz it creates a generator and printing gives me useful things like..

<generator object MSSMixin.save at 0x0000020451EFBD68>

the print does nothing lol, its just running the generator. also: the author explicitly advises NOT doing any mss().xxx as it causes resource leaks

https://python-mss.readthedocs.io/usage.html

checking the function save() in the source, it returns the filename. saving the file is inherently part of the function. grab() gets you the image, save() combines that with to_png()
Python code:
for idx, monitor in enumerate(monitors[1:], 1):
    fname = output.format(mon=idx, date=datetime.now(), **monitor)
    if callable(callback):
        callback(fname)
    sct = self.grab(monitor)
    to_png(sct.rgb, sct.size, level=self.compression_level, output=fname)
    yield fname

mbt fucked around with this message at 02:15 on Feb 24, 2019

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

crazysim posted:

I like using debuggex and other online regexp tools to debug those.

I really like https://regex101.com. I used to use https://regexr.com before that but I think regex101 is nicer for whatever reason I don't remember.

NtotheTC
Dec 31, 2007


Why are people posting about writing cheat software ITT?

"It's just a research project". Uh-huh

cinci zoo sniper
Mar 15, 2013




NtotheTC posted:

Why are people posting about writing cheat software ITT?

"It's just a research project". Uh-huh

This is a programming thread on SA , not a tech support thread of official Space Station forums or whatever.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

I'm with the cops, you're all busted

NtotheTC
Dec 31, 2007


cinci zoo sniper posted:

This is a programming thread on SA , not a tech support thread of official Space Station forums or whatever.

My issue was less about white-noising the thread and more about it being scummy and maybe people should keep the blackhat poo poo they do for a dollar to themselves.

mbt
Aug 13, 2012

NtotheTC posted:

My issue was less about white-noising the thread and more about it being scummy and maybe people should keep the blackhat poo poo they do for a dollar to themselves.

Thank you for implying i get paid or even distribute my code.

Im bad at fps games and dont want to click 100 times in spacestation 13, throw me in jail :shobon:

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

NtotheTC posted:

My issue was less about white-noising the thread and more about it being scummy and maybe people should keep the blackhat poo poo they do for a dollar to themselves.

if space station 13 were a competitive game where people were actually trying to win or lose, it might be scummy, but ss is a heavily moderated western RPG-style game with no set win conditions.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I enjoy the idea of automating games (particularity clicky web games) that aren't competitive. (gently caress you if you're writing cheats for overwatch or something).

I hope people continue to post about that poo poo. One day I hope to get through my huge list of projects that sound fun and maybe try my hand at doing something like that.

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
Clicky web games, you can often just edit the js directly or mock parts of the api or figure out the save format

QuarkJets
Sep 8, 2008

NtotheTC posted:

My issue was less about white-noising the thread and more about it being scummy and maybe people should keep the blackhat poo poo they do for a dollar to themselves.

Maybe you should keep your opinions to yourself instead since you don't seem to know what you're talking about

What that dude is doing is basically AutoHotKey with an image processing layer, and he's applying to possibly the least competitive multiplayer game in existence; there's nothing really "blackhat" to talk about there. He also wasn't "white-noising" the thread, he explained exactly what he was doing and even provided a movie of it in action.

NtotheTC
Dec 31, 2007


QuarkJets posted:

Maybe you should keep your opinions to yourself instead since you don't seem to know what you're talking about

What that dude is doing is basically AutoHotKey with an image processing layer, and he's applying to possibly the least competitive multiplayer game in existence; there's nothing really "blackhat" to talk about there. He also wasn't "white-noising" the thread, he explained exactly what he was doing and even provided a movie of it in action.

The first post says "im writing cheat software", the second post says "here's how you'd do it for Apex" and the video is literally titled "cheating in space station 13". So why would anyone think it strange? I didnt set the tone or the topic.

I imagine automation- ahk or otherwise is listed as cheating even in a web game so who cares if it's the equivalent of botting in slither.io? How is it a contraversial opinion to say "don't talk about writing cheats ITT?“ there must be thousands of legitimate uses for that sort of tooling so use those to demonstrate it.

punished milkman
Dec 5, 2018

would have won
I asked about it because capturing image data from video games, processing it, analyzing it, and then responding with simulated input, is (to me at least) a very interesting technical problem worthy of discussion in a thread about Python. No one is talking about breaking terms of service agreements or laws or anything. I was thinking about writing a bot for some SNES platformer or something dumb like that.

mbt
Aug 13, 2012

NtotheTC posted:

The first post says "im writing cheat software", the second post says "here's how you'd do it for Apex" and the video is literally titled "cheating in space station 13". So why would anyone think it strange? I didnt set the tone or the topic.

I imagine automation- ahk or otherwise is listed as cheating even in a web game so who cares if it's the equivalent of botting in slither.io? How is it a contraversial opinion to say "don't talk about writing cheats ITT?“ there must be thousands of legitimate uses for that sort of tooling so use those to demonstrate it.

Saying 'learn cpp and write dll wrappers' isnt some arcane secret. Its more of saying 'hey if you want to actually cheat DONT do this, its the least efficient way to do this and involves more computational power than god" Maybe it didnt come across but being able to 'get sick headshots in apex' via python image capture is not possible no matter how you slice it.

Writing automation software for games is how lots of people get into programming to begin with, including myself. Eventually you get a real job and begin to think back on cheating on cookie clicker and translate those same exact functions to legitimate uses. It doesnt take a phd to say 'programs that move your mouse and keyboard can be used to cheat in games' lol

Dominoes
Sep 20, 2007

Using the Python reddit as an example, there are several topics less constructive than game cheats: Banal blog posts/Medium articles, framework/A vs B, political package-manager chat, popularity statistics etc.

QuarkJets
Sep 8, 2008

NtotheTC posted:

The first post says "im writing cheat software", the second post says "here's how you'd do it for Apex" and the video is literally titled "cheating in space station 13". So why would anyone think it strange? I didnt set the tone or the topic.

I imagine automation- ahk or otherwise is listed as cheating even in a web game so who cares if it's the equivalent of botting in slither.io? How is it a contraversial opinion to say "don't talk about writing cheats ITT?“ there must be thousands of legitimate uses for that sort of tooling so use those to demonstrate it.

I never said that it wasn't cheating, I said that it wasn't "blackhat". However what's being discussed is a legitimate use of programming and that's what people are pointing out to you.

As always, the context matters a lot; in a context where you're combining keypresses for convenience, rather than as a substitute for skill, it's generally not considered malicious. For instance any game where abilities have cooldowns (games like MWO, most RPGs, most MMOs, etc) a key-pressing script provides no competitive advantage. World of Warcraft basically has AHK built into it, you can automate all sorts of mundane poo poo but you'll get banned if you start to automate something that occurs during a competitive context, such as combat. In the context of SS13, "combining ingredients in a specific order" is not really a skill, assuming you have motor and memory skills exceeding a toddler, so automating those steps is for convenience rather than to gain a competitive advantage (also it's not a competitive game).

When you said "white noise" I thought you were referring to your out-of-nowhere "oh this is just a research project" comment, which implied that he was being secretive or something when he clearly wasn't. If that wasn't your intention then I guess you sometimes just randomly type words into the comment field and that's a harmless enough form of entertainment

NinpoEspiritoSanto
Oct 22, 2013




Can we not goon up what had until now been a nice, interesting and informative thread, with a stupid slapfight thanks just thanks.

Person who posted the screenshot stuff, I found it very interesting and always like to find more performant ways of doing things thank you.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Bundy posted:

Can we not goon up what had until now been a nice, interesting and informative thread, with a stupid slapfight thanks just thanks.

Person who posted the screenshot stuff, I found it very interesting and always like to find more performant ways of doing things thank you.

This, I really enjoyed the MSS chat as I've used both OpenCV w/python and pyautogui but hadn't heard of MSS

Hadlock
Nov 9, 2004

The last four or so companies that reached out to me were all about screen scraping old lovely enterprise applications for data entry and poo poo, basically replacing all the 60 year old gray haired $65,000/yr accountants with a couple of ec2 instances at $60/month.

It all sounds like bullshit but VCs keep throwing about $60 million a year at the problem to a couple dozen companies each year so there's at least a legit purpose for the technology, even if the task is mind numbing drudgery.

The computer doesn't care if it's playing space station 13, sudoku, crossword puzzles, or validating field expense reports and balancing the sales teams' monthly budget.

Hadlock fucked around with this message at 11:44 on Feb 25, 2019

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
Bit of a Hail Mary request and not entirely Python but:

We have a database stored in Netezza (an old IBM data warehouse). Our legacy in-house solution to connect to it involves using a Windows SQL workbench. I'd rather (2) use Linux or OSX and (2) do it from a script with a proper programming language like Python. And it's getting complicated:

* Hey, you connect to Netezza with odbc! I'll just use pyodbc!
* Uh, but you still need the odbc drivers for Netezza, which IBM won't give to me. I need a license.
* (I ask the in-house IT for the drivers. Radio silence ...)
* Uh, mxODBC says it can connect to Netezza ... if I can install something on the server. Nope.
* There's a bunch of solutions on the web about using pyodbc to connect to Netezza ... all of which gloss over the driver step
* Here's a few other commercial / shareware solutions that say they can connect to Netezza but it's unclear if they really can or if they just use the aforementioned drivers.
* Someone suggests just copying the driver from the PC installation ... but I can't seem to find a matching jar file.

Any leads here? I feel like I'm chasing my tail. And any opinions on pyodbc? Some aspects of it seem under-documented but that might be my inexperience.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Boris Galerkin posted:

I'm digging into tox right now and it's a bit confusing. Is tox suppose to only run tests or do people use it for more than that? Here's what my simple tox.ini file looks like right now:

test library idea: toxx. adds a new form of assertion, where if it ever fails, it logs into the forums with your account ...

bonus: idiots checking their forums password into github

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!

Soricidus posted:

test library idea: toxx. adds a new form of assertion, where if it ever fails, it logs into the forums with your account ...

bonus: idiots checking their forums password into github

I don't get it, but speaking of tox I just saw my .tox folder is 1.6 GB. The actual code itself isn't even 1 MB.

What the hell is ballooning my .tox folder and is there any way to stop this from happening? Hard drive space is cheap but my MacBook only has 512 GB total so this is going to add up if I start using tox for everything.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



baka kaba posted:

I'm with the cops, you're all busted

I'm writing iOS malware in Python come at me bro

I also appreciated the MSS/OpenCV chat thanks everyone

Razzled
Feb 3, 2011

MY HARLEY IS COOL
If I want to write real time "tail -f"-able logs in python, I want to set buffering to 0 when I call .write(), yeah?

Gangsta Lean
Dec 3, 2001

Calm, relaxed...what could be more fulfilling?

Razzled posted:

If I want to write real time "tail -f"-able logs in python, I want to set buffering to 0 when I call .write(), yeah?

Is there any particular reason you aren’t using Python’s logging module?

Razzled
Feb 3, 2011

MY HARLEY IS COOL

Gangsta Lean posted:

Is there any particular reason you aren’t using Python’s logging module?

I guess simplicity? I mostly write scripts to help myself, not applications. I just need this thing to update me while it works so I can tail a log file and see where it's at

KICK BAMA KICK
Mar 2, 2009

logging owns, it's up there with itertools and collections for things you'll find yourself trying to do that someone else has already implemented excellently. Won't guarantee it solves your problem but take a minute to look at the basic interface and FileHandler and there's a very good chance it at least makes your code simpler and more readable.

LongSack
Jan 17, 2003

I'm a C# programmer trying to convert some code to python, and I'm having an issue with class static methods. Let's say I have an IP class that contains Address, Mask and a Status. The class also has a static method to print the address in dotted-decimal notation (go with me here, this is not the actual application i'm working with, that's proprietary enough that I can't post it here, so this is a proxy). In C#, I would have:
C# code:
public class IP
{
  public uint Address  { get; set; }
  public uint Mask { get; set; }
  public IPAddressStatus Status { get; set; }
}

public static string ToDD(uint address) 
{
  int o1, o2, o3, o4;
  o1 = (address >> 24) & 0xFF;
  o2 = (address >> 16) & 0xFF;
  o3 = (address >> 8) & 0xFF;
  o4 = address & 0xFF;
  return $"{o1}.{o2}.{o3}.{o4}";
}
So in Python, that translates to (I think, kinda newb here):
Python code:
class IP(object):
  def __init__(self):
    self.Address = 0
    self.Mask = 0
    self.Status = IPAddressStatus.UNINITIALIZED

  @staticmethod
  def ToDD(address):
    return ".".join(map(lambda n: str(address >> n & 0xFF), [24, 16, 8, 0]))
The ToDD method works when i call it on an instance of IP, but doesn't work when I call it on the class:

>>> import IP
>>> ip = IP.IP()
>>> ip.ToDD(0)
'0.0.0.0'
>>> IP.ToDD(21230232)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
IP.ToDD(21230232)
AttributeError: module 'IP' has no attribute 'ToDD'
>>> ip.ToDD(21230232)
'1.67.242.152'
>>>


Am I fundamentally misunderstanding static methods in Python? The whole point of static class methods is that I don't have to instantiate an object to use the method. What am I getting wrong? TIA

mbt
Aug 13, 2012

Module named the same as your class, this wont get confusing!

Do: IP.ip.ToDD(29293020) or whatever numbers you want. Youre currently asking the library IP to run a function ToDD which doesnt exist, IP.py only has the class ip

Static method means you can skip the newobject = IP.ip() instantiation

LongSack
Jan 17, 2003

Meyers-Briggs Testicle posted:

Module named the same as your class, this wont get confusing!

Do: IP.ip.ToDD(29293020) or whatever numbers you want. Youre currently asking the library IP to run a function ToDD which doesnt exist, IP.py only has the class ip

Static method means you can skip the newobject = IP.ip() instantiation

Thank you!

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Razzled posted:

I guess simplicity? I mostly write scripts to help myself, not applications. I just need this thing to update me while it works so I can tail a log file and see where it's at

logging library is what you should be using. It's simple for simple use cases. It's complicated for complicated use cases.

LongSack
Jan 17, 2003

Is there a good alternative to IDLE for interactive Python?
My beefs are:

1. it always starts up a shell in its own directory, so every time I restart the shell, I need to “include os” then “os.chdir(...)” to get to the directory of the project I’m working with, and
2. there doesn’t seem to be a way to paste multi-line code into the interpreter, I always get an error message, so I find myself typing the same poo poo over and over, and
3. There is no way to reload an “include” without restarting the shell which is what makes the above 2 items so frustrating
4. (Edit) up arrow is totally loving useless

Maybe I don’t know what I’m doing with IDLE (always a possibility), but man this is irritating.

Dominoes
Sep 20, 2007

Ipython/QtConsole

Hadlock
Nov 9, 2004

I have some slow/heavy api calls i have to make on every page load in Django, page load time is almost 10 seconds, and will soon be doubling the number of api calls

Thinking about setting up celery to run the queries every 15 seconds and then cache the results to a table in the db.

Is this the right way to do this? I can setup a redis container but reading the docs it sounds like postgres is supported out of the box.

Each api call returns about 1000 key value pairs in json format, that part is pretty inflexible

Django 2.1 and python 3.7

pmchem
Jan 22, 2010


LongSack posted:

Is there a good alternative to IDLE for interactive Python?
My beefs are:

1. it always starts up a shell in its own directory, so every time I restart the shell, I need to “include os” then “os.chdir(...)” to get to the directory of the project I’m working with, and
2. there doesn’t seem to be a way to paste multi-line code into the interpreter, I always get an error message, so I find myself typing the same poo poo over and over, and
3. There is no way to reload an “include” without restarting the shell which is what makes the above 2 items so frustrating
4. (Edit) up arrow is totally loving useless

Maybe I don’t know what I’m doing with IDLE (always a possibility), but man this is irritating.

You might enjoy an interactive development environment such as Spyder. It's installed by default with Anaconda python distrib.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Hadlock posted:

I have some slow/heavy api calls i have to make on every page load in Django, page load time is almost 10 seconds, and will soon be doubling the number of api calls

Thinking about setting up celery to run the queries every 15 seconds and then cache the results to a table in the db.

Is this the right way to do this? I can setup a redis container but reading the docs it sounds like postgres is supported out of the box.

Each api call returns about 1000 key value pairs in json format, that part is pretty inflexible

Django 2.1 and python 3.7

I usually default to using my database as a cache and then moving on to redis or something like it when my performance degrades enough that I need to introduce the extra complexity.

That being said, I'd possibly use python-rq instead of celery. You add extra complexity because you have to use redis, but you lose complexity because python-rq is way simpler to configure and write for than celery.

LongSack
Jan 17, 2003

pmchem posted:

You might enjoy an interactive development environment such as Spyder. It's installed by default with Anaconda python distrib.

Thanks, that hits the spot. I can reimport my modules, the up-arrow works, and I don't have to keep alt-tabbing between IDLE and Notepad++

Adbot
ADBOT LOVES YOU

pmchem
Jan 22, 2010


LongSack posted:

Thanks, that hits the spot. I can reimport my modules, the up-arrow works, and I don't have to keep alt-tabbing between IDLE and Notepad++

Spyder is a really great, open source / free, lightweight, python-native piece of software that needs more appreciation in the community. I love it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply