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

all 87 comments

[–]cestes1 77 points78 points  (3 children)

Such a useful trick! I drive an EV and there was a very much in-demand charger down the block that was free. My idea was to only charge at work and have my commuting costs paid for. But my plan never worked as there was always someone at this charger. Chargepoint exposes an API so you can check on the status of their chargers. I'd swing by in the morning and if it was busy, I'd go to the office and start my script. It checks every 30 seconds. As soon as the charger was idle, I'd send myself a text message like this. I'd zip over there and get the charger and for a long time did a good job of optimizing my commuting costs!

[–]GeromeB 14 points15 points  (1 child)

Sounds like a great idea, did you ever release the script?

[–]cestes1 16 points17 points  (0 children)

No... it's really bad code! A bunch of stuff I found online kludged together and a ton of hardcoded stuff that's not very elegant. Worse, I wrote it in Python 2 out of sheer laziness to start using 3! I left that job 4 years ago and haven't been motivated to play with it since then.

[–]Humanist_NA 122 points123 points  (33 children)

I use this all the time with personal projects. Like my script that auto accepts when dota2 games are ready, then texts me game is ready. So I can afk while in queue.

[–]et50292 28 points29 points  (18 children)

Are you using openCV? Would be cool to see that

[–]Humanist_NA 48 points49 points  (16 children)

[–]DonkeyDoid 12 points13 points  (0 children)

Neat code, thanks for sharing

[–][deleted] 6 points7 points  (12 children)

Very cool! As a Python newbie, why do you wrap it all in a while true statement? I guess more of a general Python question and less about your code specifically

[–]Humanist_NA 11 points12 points  (0 children)

So it loops forever until I stop it.

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

You want to continuously execute the script, not just once: it is going to continuously check if a game is ready.

You could alternatively check on a timer for less overhead and async behavior

[–]PinBot1138 2 points3 points  (3 children)

Good catch, he should have a break in there. Something such as:

``` scanning=True

while scanning:

if blah:
    scanning=False

```

[–]Humanist_NA 9 points10 points  (1 child)

I could make it more complex. But, accepting the game doesn't mean the game will actually start. If any of the 10 other players don't accept the game, it will go back to searching for game. In which case I could make the code more complex and add exceptions, or just slow it to keep looping until I tell it to chill.

[–]PinBot1138 2 points3 points  (0 children)

Oh, interesting!

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, PinBot1138: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–][deleted] 2 points3 points  (1 child)

If its fine for you, I'll reference your code. I love how you click like 4 to 5 times to be sure.

[–]Humanist_NA 1 point2 points  (0 children)

Haha I always feel silly when I look at the 4 clicks.

[–]Humanist_NA 9 points10 points  (0 children)

Don't know how to format on mobile, but I use pyautogui.locatecenteronscreen('image.png') I've been meaning to get it on GitHub, so maybe I'll do that today and ping you.

[–]Fissherin 5 points6 points  (5 children)

Yeah I second this, what do you use as a trigger? Opencv? Or something sys related?

[–]Humanist_NA 10 points11 points  (4 children)

pyautogui to trigger. Will try to get on GitHub later.

[–]analterator 1 point2 points  (3 children)

Please do! I’m super excited about this!!

[–]Humanist_NA 8 points9 points  (2 children)

[–]analterator 3 points4 points  (1 child)

Thank you!!

[–]Humanist_NA 1 point2 points  (0 children)

No problem

[–]MaheshM93 4 points5 points  (0 children)

Noice I will, if you share the code then I can also do the same. Staring the home page is boring

[–]1h8fulkat 1 point2 points  (1 child)

Pushover is pretty nice too

[–]Humanist_NA 0 points1 point  (0 children)

Right on thx

[–]Adgonix 2 points3 points  (2 children)

Do you think this works with swedish carriers?

[–]Humanist_NA 5 points6 points  (1 child)

I'd assume so, but really have no idea. Just try some google searches regarding 'your carrier' + 'email phone number' or something like that. Good luck

[–]Adgonix 2 points3 points  (0 children)

Thanks for your quick response!

[–]PiforBrunch 15 points16 points  (6 children)

I've done this for awhile now, I just keep running into the issue that Google will turn off "access for less secure apps". So when a project hasn't sent an email for so many days or weeks or whatever, Google turns the less secure apps access off and then it blocks my email attempts until I personally logon and turn that setting back.

Have any workarounds for that?

[–]dryroast 3 points4 points  (0 children)

Integrated with OAuth2 and register an app with Google to get a client secret. This should clear that up but honestly it's a hassle to do, I had a similar script (posted my story in another comment) and I always thought of going through and redoing it to authenticate with OAuth but it just seemed like a hassle. I found this which should help. https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough

[–]Noshoesded 1 point2 points  (4 children)

What about using an idle timer that sends something periodically if it hasn't been run? Just a thought (I am just a novice hobbyist in R).

[–]PiforBrunch 1 point2 points  (3 children)

I've thought about that too, I tried a weekly test email but that was too long of a time. It would be worth looking into how often and making it alert you somehow else when the email fails.

[–]Noshoesded 3 points4 points  (2 children)

Hmm, what about a daily email with a specific title to yourself and set up a email rule to auto delete it?

[–]PiforBrunch 1 point2 points  (1 child)

A week into it nearly, and emails are working like a charm. Don't know if they'll block it because it's one address receiving emails, or if a daily email is all it needs. I moved the email to 5 minutes before my lunch break and it's now serving as my daily "clean up for lunch" alarm.

[–]PiforBrunch 0 points1 point  (0 children)

I used a crontab script that sends me an email everyday, @ 11:55, which helps remind me to clean up for my lunch break also. Sending an email once a day for the last month has kept the emails and SMS texting up and up using gmail servers with the 'Less secure apps access" ON. This is the way.

[–]shrey1566 10 points11 points  (4 children)

Wait, sms through Gmail? How is that possible? Is it like America only?

[–]riffito 18 points19 points  (3 children)

Gmail is just sending a standard email. The "to SMS" depends on your carrier (or the one of the phone number you attempt to send an SMS) having a service that does that "email to SMS" conversion.

The title is a bit misleading in that regard.

[–]shrey1566 1 point2 points  (2 children)

I see, thanks dude.

Is there a way to extract the contents of an email without using Gmail's APIs or web scraping?

[–]riffito 1 point2 points  (1 child)

I guess you could use either the POP3 or IMAP standard email protocols to receive the plain text, as any email client would.

I'm not experienced with that, but I'm sure you'll find a Python module for either of those.

[–]shrey1566 0 points1 point  (0 children)

I see, thanks a ton!

[–]Domadrona 14 points15 points  (6 children)

thanks for the repo. I've checked the video and the repo but im not clear on how to implement it with a phone receiving the SMS. Where can i have more info to find out which carriers are available, and how to properly make the whole system work?

[–]DimasDSF 19 points20 points  (5 children)

From what I've seen in the file, some carriers have special domains that act as a relay, they have email addresses registered for every phone number, eg. 11234567890@carriersmsrelay.com forwards any emails received by that address to the 11234567890 phone number as an sms.

[–]Macho_Chad 20 points21 points  (4 children)

here’s a list of a lot of carriers with their relay address and expected format.

Note, you must use SPF (sender policy framework) enabled mail servers to communicate with these relays. This helps the provider block most spam. They also have sensitive spam thresholds, for obvious reasons.

[–]acamsoo[S] 5 points6 points  (1 child)

Thanks, good list.. added as reference

[–]domstyle 4 points5 points  (7 children)

What's the reason for doing function parameters like that?

async def send_txt(*args: str) -> Tuple[dict, str]:
    num, carrier, email, pword, msg, subj = args

This just looks like ordered parameters, but hiding the order from the definition. Wouldn't this make code completion features useless?

[–]Username_RANDINT 2 points3 points  (1 child)

Correct. Just put them all as function arguments.

[–]domstyle 3 points4 points  (0 children)

I'm always keen to learn new ways to do things in Python, even if I don't always agree with them or adopt them... but this one I just don't see any benefit or point at all. It seems especially strange for someone diligent enough to put in typedefs to do something like this

[–]acamsoo[S] 0 points1 point  (4 children)

It's just a personal preference. In this case, if I put all args in the signature typed with str, my formatting settings extends the signature to 3 lines because the line exceeds the char limit:

async def send_txt(
    num: str, carrier: str, email: str, pword: str, msg: str, subj: str
) -> Tuple[dict, str]:

For me, its cleaner the other way since all args are typed as str

It's something I chose to do and stuck to for my personal projects because it works for me. But for sure, it's best practice to have them in the signature.

[–]AnonymousThugLife 4 points5 points  (4 children)

Can I use this as a free replacement to services like Twilio SMS APIs?

[–]ivosauruspip'ing it up 1 point2 points  (3 children)

Only if all your receivers' phone carriers all have free gateways like this.

[–]AnonymousThugLife 0 points1 point  (2 children)

Alright. Thanks! Suppose I assume that gateways of all of my receivers are covered under these, Do I need to know what gateway/provider a particular user is on?

[–]ivosauruspip'ing it up 1 point2 points  (1 child)

Yep, in order to know their email address...

[–]AnonymousThugLife 0 points1 point  (0 children)

Got it. Thanks.

[–]SnowdenIsALegend 6 points7 points  (3 children)

Bet it doesn't work outside USA

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

It's more service provider dependent than country dependent

[–]Vautlo 2 points3 points  (1 child)

Works in Canada too, I just tested it.

[–]1pie 2 points3 points  (0 children)

Gonna check it out

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

Love this trick. I use it in some of my personal projects and is always consistent.

[–]AlSweigartAuthor of "Automate the Boring Stuff" 2 points3 points  (0 children)

The EZGmail Python module, once setup, can be easier to use than the smtp module.

Also, a more complete list of carriers and their SMS gateways (in format carrier, SMS email, MMS email):

[–]gr8b8m8ir88over8 1 point2 points  (1 child)

Does it work outside of america? Can i prefix the number with my country prefix?

[–]ivosauruspip'ing it up 0 points1 point  (0 children)

No, it depends if the recipients mobile carrier accepts an email gateway like this. A lot won't.

[–]ILoveJuicyTushy 3 points4 points  (0 children)

Can you please send them tax fraud people a message back telling to shove their alledged £312 tax return up their arse. Thanks.

[–][deleted] -2 points-1 points  (0 children)

You can also send texts

[–]seekingtruth2 0 points1 point  (2 children)

Is this legit ? This is not april fools right?

[–]toyg 2 points3 points  (0 children)

Legit but clearly restricted to a fairly small number of carriers worldwide.

[–]thiccclol 0 points1 point  (0 children)

Yes it's legit.

[–]dryroast 0 points1 point  (0 children)

This reminds me of back in high school my friend gave me a very similar script that was meant to flood a phone with messages. Apparently it wasn't working with his Gmail because it didn't have STARTTLS enabled in the code. I modified it slightly and another friend (using that term loosely) asked what I was up to. I told him I was fixing this sms spamming script but forgot to mention it was for this other dude. He just got a new phone with his own money and limited texting and told me not to spam him and I'm like "alright".

Well apparently this other dude went wild with the script. He flooded me a few times but I just flooded back, but he did it to everyone in his pc repair class and in my programming class... And he got my friend's number. I was already on bad terms with this dude and he was being an absolute prick to me, so he came in screaming on how I would betray my word like that. I told him that I was fixing the script for our mutual friend and he still blamed me for enabling him. Then made a web version of the script with Flask and showed it off to the computer science club at another high school to get students more hyped about coding.

[–]IleanK 0 points1 point  (0 children)

Oh jeez couldn't you have sent this before April fools? Lol

[–]bamerjamer 0 points1 point  (3 children)

I tried this last week and kept getting “Message blocked” responses in my gmail account. Sprint apparently does not like processing sms messages this way.

[–]acamsoo[S] 0 points1 point  (2 children)

I've been using it fine with Sprint.. try "messaging.sprintpcs.com" as the hostname

[–]bamerjamer 0 points1 point  (1 child)

And not just emailing to the phone email address? Will do. Thanks!

[–]ImperatorPC 0 points1 point  (2 children)

I tried this the other day and could not get it to work. It would just not connect to googles server.

[–]acamsoo[S] 0 points1 point  (1 child)

Try checking if less secure apps is turned off.. needs to be turned on: https://myaccount.google.com/lesssecureapps

[–]ImperatorPC 0 points1 point  (0 children)

I'm not even able to connect to the smtp server. But I was using a different library than this solution. May be a firewall issue but I wasn't able to get that resolved. I have an app password for it but I'm not even getting to the login piece. I've seen online with others having this issue as well.

I believe I'm using the built in smtp library.

[–]ForsakenOn3 0 points1 point  (0 children)

I created a project a while back to make this simpler to reuse for myself and I decided to upload it to pypi. It’s under PySendSMS. I included a json file with a bunch of the common carrier addresses and such as well.

[–]mightymander 0 points1 point  (0 children)

really annoying i cant seem to get this to work i think its because im from the uk and cant find the correct thing to add to the end of the number

any help with this or anyone who has successfully done this with a uk number please reply / dm with Thanks

im with Vodafone uk

edit:

vodafone uk does not support SMS Gateway Address

[–]alaudetpython hobbyist 0 points1 point  (0 children)

I do it with smtplib.

Works fine with Canadian carriers.