[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

What are you working on /g/? I wrote a program that will au

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 22
Thread images: 3

File: python.png (50KB, 727x255px) Image search: [Google]
python.png
50KB, 727x255px
What are you working on /g/?

I wrote a program that will automatically email my girlfriend once each day while I'm gone innawoods

#! /usr/bin/env python3.

import smtplib
import schedule
import time

def emailThis():
mail = smtplib.SMTP('smtp.gmail.com', 587) #Creates SMTP object
type(mail) #Makes sure 'mail' is an SMTP object

mail.ehlo() #Helps establish connection to the server

mail.starttls() #Enables encryption for connection

mail.login('top', 'kek') #Logs into mail
#235 as return value
#indicates successful
#connection
mail.sendmail('top', 'zozzle',
'Subject: Daily Reminder. \nI love you a ton!')

mail.quit() #Closes connection

schedule.every().day.at('00:35').do(emailThis)

while True:
schedule.run_pending()
time.sleep(60)

#run program with:
#nohup python3 autoEmail.py &
#kill program with
#kill *PID number given after running*
>>
>>60850800
Fag.
>>
>>60850804
>Fag
>Has a girlfriend

At least it's not a waifu.
>>
>>60850800
>I wrote a program that will automatically email my girlfriend once each day while I'm gone innawoods
>>
that seems pretty obnoxious or she sounds pretty needy. take your pick
>>
>>60851016
Or it's cute and funny, depends on the relationship
>inb4 samefag
>>
>>60851061
there's no spontaneity in the email. it's the same dumb subject and message every day at 12:35am when you're in the woods. that kind of gesture gets extremely tedious after 2 or 3 iterations. if she hasn't filtered it after a week's worth of that email in her inbox, there's something wrong with her.

at least put in a set of cute shit to say like references to good things in your relationship (like your first date or her favorite food or whatever. literally, anything that demonstrates you think about her) and randomly pick one of them to put in the message. or *something*.

this is a bizarre mix of effort/explicitness and utter laziness. like you're *drawing her attention* to the fact that you're half-assing it. if you're going to be out of contact, just be out of contact. if you're going to feel guilty about it, make it up to her when you get back. but don't do these impersonal half-measures.

and none of this is even talking about the shittiness of your code. `type(mail)` doesn't ensure that mail is an SMTP object. it just returns the type. to ensure that the type is correct, you need to *compare* it against something. preferably compare to make sure it's an SMTP object, if that's what you want (which from your comment seems to be the case). see lines 3 and 4.

and for fuck's sake don't EVER put login credentials in your code. put them in an environment variable or in a settings file or something. see lines 5-9
>>
>type(mail) #Makes sure 'mail' is an SMTP object

Normally mistakes and misconceptions can be excused, but because you're so cocky and smug about your babby's first programming, you should kill yourself you utter retard.
>>
>>60851328

wow ur such a hacker pls don't hack us :D

Kill yourself too, because of your cringe-worthy, bragging in your screenshot.
>>
>>60851328
this guy gets it
>>
>>60851436
what the hell is bragging in my post? it's just an illustration of what i'm talking about. are you one of those dumb niggers that thinks a magic trick is actual magic?
>>
>>60851584

With your cringeworthy printing of environment variables and reading JSON formatted data, idiot. The fact that you think that was cool or impressive enough to include shows how smug you are about your babby's first programming related topics.
Kill yourself.
>>
>>60850800
Holy fuck Python is so fucking garbage, I get sick looking at this dumb shit.

Why didn't you just use PHP for this shit, it would been like three lines.
>>
>>60851584
GNUmale Lincuck is just mad he can't afford a Mac, ignore him.
>>
>>60851328
This is the best post I've read in 2017
>>
>>60850800
Seems you're new to this, OP. I'll take it as you're trying to crowd source advice, rather than showing off your... code. Best way to get someone to help you with something on the internet is by being wrong, after all.

(1) Scheduling
I don't consider your script running on a while True loop good practice. You can easily schedule this script to run once per day with something like crontab. Most linux distros (which I assume you are using since you include a shebang in the first line) will have some variation of this.

(2) Unlike anon at >>60851328 I see what you mean when you use type(mail). I assume you are trying to include a sort of log with nohup's autogenerated nohup.out log file. Frankly, you'd want at least a print(type(mail)) in there before it shows up in nohup.out. Best practice is to use the logging module. Even better is to catch a type error with try/catch; and log it with logging.

Note that logging module has quite a lot of depth, but at the same time you can use it casually; i.e. beginner friendly but fully-featured if you know how to use it.

(3) As anon at id above has pointed out, vary your messages. Do some madlibs shit. You can save message templates in one file (one per line), and pick one at random with randomint(). You can save words in another, and blah blah so on.

Read up on using file I/O (i.e. file.open(), etc.)
>>
>>60850800
To add on to my previous post, this dude >>60851328 seems to think you're bad because you lack effort or something. I think you're bad because you're bad. You're clearly new to coding (or python, at least), and this is the best you could have come up with.

Keep it up, though. Everyone starts out like this.
>>
>>60850800
The fuck is with your commenting!
>>
Got a question here

How do i open a file that's already running in the taskbar with python. As in, i've tabbed out from a video game and i'd like to open it automatically.

aight thanks.
>>
>>60850800
you wrote a program that gave me cancer
>>
>>60853946
whaaaaaaat?
you mean like alt tab or open a text file?
Thread posts: 22
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.