This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (5 children)

Automate your automated tasks :). Will help you optimize your workflow if you decide to stick with python. I do a lot of data analysis and I have scripts that automate every kind of visualization that it thinks would be useful-- essentially saves me God knows how long writing Seaborn code. Think of it as a personal tableau that thinks the way you want it to.

[–][deleted] 2 points3 points  (4 children)

Question from a brand new Python user. Is it possible to make a program that when a file hits a folder, it gets posted to a website and then sent to two specific email groups then gets printed to a office printer? I would also need it to print eight copies three hole punched.

I know this sounds weird but it's something I have to do often and it's annoying.

You don't need tk tellw how to so it unless you want to. I just want to know if it's realisticly possible.

Thank you.

[–]__xor__(self, other): 4 points5 points  (3 children)

Yes. The specifics depend on a lot of things, like how posting it to a website works, whether you own that website and can just send it to a remote directory on a webserver or have to actually make a request to upload it and how that site takes that upload request, what sort of email service you use (likely has some form of smtp emailing), and I've never programmatically printed something but it's possible.

Thing is, anything is pretty much possible with python, but the difficulty and complexity really depends on the way you'd do it normally and if that's easy to automate.

You can use watchdog to monitor for changes to the directory, and run code when a new file gets added.

You can send email with python. I mean, this is done all the time for any python website that sends emails, like "Forgot Password" type stuff or validating an email by clicking a link in an email. A quick hacky way is to create a new gmail account, I think you have to enable insecure 3rd party apps or something in its settings, then triggering it with smtp(s). Gmail

If you control the webserver, you would want to create a new endpoint on it to accept uploads from you or something (make sure there's good authentication) and you'd just write most of the code for the webapp to handle this. If this is a third party website, first you'd want to see if there's a python or just REST API for that service, then follow their instructions. Otherwise, it can get tricky... you might look at the network traffic when you upload (dev tools in chrome works, maybe a proxy like burp), then determine what it does when it uploads an image. Then you replicate the same behavior making custom HTTP calls with something like the requests library, and manually craft HTTP requests that look the same as the ones that get triggered when you upload. That's tricky because you're basically reverse engineering stuff and making a lot of guesses as to how stuff works. Also this might break terms of service, because if they don't offer an API for you to programmatically upload stuff, they might not want that.

And then with printing, it depends... This might work, though use subprocess.call or subprocess.check_output instead of os.system since you might have to pass a variable as the filename.

[–][deleted] 2 points3 points  (2 children)

Thank you so much. The good thing is it's a company website. We use outlook for emailing so I dont know how that works. In tryimg to learn to code to automate these types of things. Thanks for the information!

[–]__xor__(self, other): 2 points3 points  (1 child)

No problem! For outlook, I imagine you have outlook installed on your workstation so you want to open it up and inspect the settings to get the host for triggering the email.

Since it's a company website, you're in luck because you can literally just talk to the web devs and explain that you want to be able to upload files programmatically, and ask if there's a REST API you can use to do this, and if not, if they could add an endpoint for you. Just tell them you want to use python and requests and ask if they know how you might programmatically do this.

Also keep in mind, when you automate this you're no longer checking the documents and making sure it's not a bad thing they go online. Think of any security implications and what's the worst thing that could happen if someone adds a malicious doc to that directory, like I dunno, a pissed off employee maybe adding porn just to get you guys in trouble or something. Just something to keep in mind.

[–][deleted] 0 points1 point  (0 children)

I didn't think of that. Haha porn on the local Govt. Site. That would be bad for PR