r/Python • • Aug 28 '20

Beginner Showcase This post has

3829 upvotes,

572 downvotes,

297 comments,

3257 score,

and 3 awards!

Edits: 23526 since Friday, August 28, 2020 at 8:30PM EST.

Credit to u/Krukerfluk and Tom Scott!

Code: https://github.com/CalvinMiller190/reddit-post

This post uses the praw module to get the information about the post, then edits the post every second based on the information that it got!

3.4k Upvotes

276 comments sorted by

185

u/[deleted] Aug 28 '20 edited Aug 29 '20

Or does it? *Votes, reloads, unvotes, reloads

6

u/[deleted] Aug 28 '20

:0

26

u/[deleted] Aug 29 '20

who did you invite?

16

u/[deleted] Aug 29 '20

25 upvotes and nobody mentioned this. What has the world come to?!

0

u/[deleted] Aug 29 '20

[deleted]

→ More replies (1)

12

u/Maoman1 Aug 29 '20

That won't really work since reddit fuzzes post scores. Reload the page a few times in rapid succession and the number of votes will randomly go up and down quite a bit.

9

u/kdedev Aug 29 '20

Or does it?

Vsauce music intensifies

105

u/Config_Crawler Aug 28 '20

This is pretty cool.

81

u/[deleted] Aug 28 '20

thanks! although i must give a bit of credit to tom scott, the guy who did the youtube view count video.

0

u/[deleted] Aug 29 '20

[deleted]

1

u/[deleted] Aug 29 '20

My exact inspiration :)

138

u/[deleted] Aug 28 '20

Ok

59

u/[deleted] Aug 28 '20

i hope this works lol

30

u/[deleted] Aug 28 '20

Wow looks like it is Edit: it says 0 upvotes but I upvoted

46

u/[deleted] Aug 28 '20 edited Aug 28 '20

it updates every minute
Edit: Now it updates every second

11

u/dgriffith Aug 29 '20

There's no rate limiting in Reddit's API?

4

u/[deleted] Aug 29 '20

im using the praw module, i dont know about API, but it seems to work fine as it is

→ More replies (3)
→ More replies (1)

25

u/[deleted] Aug 28 '20

It updates faster than my UI lol

5

u/Sw429 Aug 28 '20

Good work lol

21

u/iamemu Aug 28 '20

Reminds me of a Tom Scott video

13

u/[deleted] Aug 28 '20

that was my inspiration :)

8

u/SpiritualCup Aug 28 '20

How do you get the amount of downvotes using PRAW??? Couldn’t figure it out

13

u/[deleted] Aug 28 '20

UPVOTES:

ups = round((ratio * submission.score) / (2 * ratio - 1)) if ratio != 0.5 else round(submission.score / 2)

DOWNVOTES:

downs = ups - submission.score

23

u/13steinj Aug 28 '20

Note that that formula is still an estimate, as reddit fuzzes the numbers to prevent vote manipulation.

→ More replies (6)

3

u/[deleted] Aug 29 '20

at least 10 people are upvoting then downvoting just to see it go up and down

3

u/waythps Aug 28 '20

Cool. I had a similar idea - update markdown table with a list of top voted question in stackoverflow. Super fun!

How the reddit api?

2

u/[deleted] Aug 29 '20

im using the praw module for everything!

7

u/Blobtoe Aug 28 '20

Must... Keep... The 69 upvotes.

3

u/[deleted] Aug 28 '20

so sad.. it went away

3

u/suicidal-rabbit Aug 28 '20

It had 69 downvotes just now, so yay... I guess? Haha

3

u/[deleted] Aug 28 '20

even better lol

→ More replies (1)

2

u/theangryfatguy Aug 28 '20

Seems to be off now

1

u/[deleted] Aug 28 '20

? it seems pretty exact

→ More replies (4)

2

u/Furkan_122 Aug 28 '20

How do you host this script?

2

u/[deleted] Aug 28 '20

nothing yet, i just have my laptop on. but i will look into using heroku in a hour or so.

2

u/GrbavaCigla Aug 29 '20

dont want to be rude, but this has been already posted here

1

u/[deleted] Aug 29 '20

yes i am aware, i was informed shortly after posting this. i had no idea, kinda crazy but i was inspired by tom scott's youtube video. after people told me, i credited the person who made the og post.

1

u/GrbavaCigla Aug 29 '20

I saw it too late ,sorry

1

u/[deleted] Aug 29 '20

no problem

4

u/IAmKindOfCreative bot_builder: deprecated Aug 28 '20 edited Aug 28 '20

Hi there, from the /r/Python mods.

I changed the flair because this submission is near a carbon copy of another submission which was also inspired by Tom Scott. But I have to remove the submission as you don't have an explanation in the title or a link to your source code, something we require for all showcase submissions. If you edit the selftext with those updates, I'll be happy to approve it,

Thank you for adjusting the submission!

Warm regards, and best of luck with your Pythoneering!

4

u/[deleted] Aug 28 '20

i wil change the title right away, and i will put the source code in the body!

5

u/IAmKindOfCreative bot_builder: deprecated Aug 28 '20

For a number of reasons, we'd actually prefer the source code to be hosted by a code hosting site suchas github or gitlab. This encourages the use of version control and helps easily introduce new programmers to these tools

4

u/[deleted] Aug 28 '20

yes, that is what i mean haha -- making the github repo now.

2

u/IAmKindOfCreative bot_builder: deprecated Aug 28 '20

Wonderful, now you'll just need a project description in the selftext and I can reinstate it!

2

u/[deleted] Aug 28 '20

sorry.. what is selftext?

→ More replies (2)

2

u/[deleted] Aug 28 '20

done! just put the source code link

11

u/irontricep Aug 28 '20

testing.... testing... testing... nice :)

8

u/Caminsky Aug 28 '20

Hi mom! I am on python 👋

7

u/[deleted] Aug 28 '20

69 incoming

7

u/mick14731 Aug 28 '20

no it doesn't

7

u/mick14731 Aug 28 '20

oh, now it does

1

u/[deleted] Aug 29 '20

thing went down for a second! it is back up now!

1

u/[deleted] Aug 29 '20

this is weirdly entertaining

1

u/[deleted] Aug 29 '20

You guys should test out the award counter. wink wink ;)

1

u/[deleted] Aug 28 '20

Holy cow! That's really, really cool! I upvoted and refreshed and got to see it change. Great job.

1

u/[deleted] Aug 28 '20

thank you!

1

u/DALLAVID Aug 28 '20

This is so cool :D I'm hoping to make something similar in the future!

1

u/[deleted] Aug 28 '20

im looking forward to seeing that!

1

u/krinistof Aug 28 '20

I've made a PR to link the word praw to the docs of it.

1

u/[deleted] Aug 28 '20

ill check it out!

1

u/[deleted] Aug 28 '20

it seems like the pull request is closed? are you making another one?

1

u/supstmkwale Aug 28 '20

Were you inspired by that YouTube vid?

2

u/[deleted] Aug 28 '20

yep! Tom Scott

2

u/supstmkwale Aug 28 '20 edited Sep 25 '20

I thought so. Good job

1

u/[deleted] Aug 28 '20

thanks!

1

u/anonymous-x-31 Aug 28 '20

You should've taken the upvote+downvote calculation into consideration, I was sitting here staring at it wondering why the upvotes were like 200+ off lol

2

u/[deleted] Aug 28 '20

idk, i like this better, it gives me insight on how many upvotes it actually has

2

u/anonymous-x-31 Aug 29 '20

Yeah fair enough, it just confused me cause I thought it was wrong

1

u/[deleted] Aug 28 '20

Yo somebody edited the main.py file like 12 seconds ago

1

u/[deleted] Aug 28 '20

yeah i did i merged a pull request that didnt do what it stated and i had to fix it

2

u/[deleted] Aug 28 '20

Nice

1

u/412gage Aug 28 '20

I’m literally going back and forth upvoting and downvoting to see it work haha

1

u/[deleted] Aug 28 '20

its pretty cool

im proud of this one haha

1

u/Death-Eye Aug 28 '20

You should add edit counter.

1

u/[deleted] Aug 29 '20

i can do that soon! really good idea!

1

u/[deleted] Aug 29 '20

done!

1

u/Jensyuwu Aug 29 '20

This is one of those pointless yet amazing things.

1

u/[deleted] Aug 29 '20

My thoughts exactly.

1

u/range_et Aug 29 '20

Noob question, whenever I have done these experiments, I gotta rent out something on linode to keep the program continuously executing / keep my laptop turned on all the time. Neither is ideal for me, how are you going about this? Any ideas on how to keep these continuous low computationally programs running?

2

u/[deleted] Aug 29 '20

I am currently using Heroku a free hosting app, and it is working quite well. you just have to make sure you have git installed and heroku CLI but you can download that once you get started. Next you would make a requirements.txt and a Procfile, requirements.txt has the non-builtin modules that are used in the projects, and Procfile just has "worker: {yourprojectname}.py". then go into heroku, and turn on the worker.

1

u/range_et Aug 29 '20

Ah okay. Any idea what the other services are or where a comparative study could be found? Like AWS Vs Linode and Heroku for example?

1

u/[deleted] Aug 29 '20

i dont.. but AWS is probably better, i just dont want to have to put my address just to host a script

→ More replies (1)

1

u/Vector3Kowalski Aug 29 '20

Yo how did you make this? Super cool man

1

u/[deleted] Aug 29 '20

if you look in the selftext, there is a description of the project and a link to the module i use.

1

u/power36113 Aug 29 '20

I upvoted, then downvoted, then un-voted and nothing happened. :(

1

u/[deleted] Aug 29 '20

it updates every second or so, and there is a lot of people doing it as well.

1

u/power36113 Aug 29 '20

I waited about one to two minutes between each action and nothing happened.

1

u/[deleted] Aug 29 '20

well thats probably why you have to do it faster -- it does work, its pretty exact

1

u/[deleted] Aug 29 '20

Quick tip, look into using environment variables so that you can have complete code in your GitHub repository. That way instead of your password looking like:

password="*******" (presumably hunter2)

It would read:

password=os.getenv("password")

Now instead of filler code for your PRAW initialization section, you can direct users to create appropriate environment variables for re-use.

1

u/[deleted] Aug 29 '20

Hmm! i might look into that, except at the moment i am using Heroku , and that requires a heroku-git repository. the one that i have in github is a exact mirror of the code, except for my client and account stuff being ****. so i dont think that i need it right now, but i may in another project. Thanks for telling me!

1

u/_Quantum_AI_ Aug 29 '20

Can it check about repost?

1

u/[deleted] Aug 29 '20

i dont think that praw can do that

1

u/Bio42 Aug 29 '20

Inaccurate for mobile

1

u/[deleted] Aug 29 '20

its not completely accurate, but it is very close. the amount of score you see under the upvote button is upvotes - downvotes, so it may be correct but is more likely 1 - 5 off.

1

u/Bio42 Aug 30 '20

I'm sorry, currently it's about 700 off..

1

u/[deleted] Aug 30 '20

but it isn’t! it is upvotes - downvotes. where it says the score is completely accurate! the score (what you see below the upvote button) is upvotes - downvotes. i don’t get how no one understands this

1

u/LegitimateCopy7 Aug 29 '20

doesn't reddit forbid frequent updates? seems like something that could be easily abused.

1

u/[deleted] Aug 29 '20

idk.. im using praw and it doesnt seem to have a problem? maybe it is something like the comment rate limit where it gets boosted up when you get more karma

1

u/-_-qarmah-_- Aug 29 '20

You're about to get ip banned from reddit lol

1

u/[deleted] Aug 29 '20

lol i should hope not..

1

u/-_-qarmah-_- Aug 29 '20

You're making way too many requests.

2

u/[deleted] Aug 29 '20

i mean.. it seems fine? the post got taken down for a bit because i didnt have any description, then once i added it, the mods read it and seemed fine with the fact that it was updating every second or so..

1

u/PsyKite Aug 29 '20

Wowwww this is an amazing shit!

1

u/[deleted] Aug 29 '20

Thanks! :)

1

u/v3ctorns1mon Aug 29 '20

Hey u/TAPTITANS3, How are you hosting the source code? Like which platform are you using?

2

u/[deleted] Aug 29 '20

I am currently using Heroku It is a free hosting app and it works quite well!

0

u/[deleted] Aug 29 '20

[deleted]

2

u/[deleted] Aug 29 '20

it doesnt seem to be, using submission.edit() has a bit of a delay to it anyway.

1

u/Kalle_022 Aug 29 '20

where do you host codes like this to keep them running???

1

u/[deleted] Aug 29 '20

im using a free hosting app called Heroku Its pretty good for a free app

1

u/myredac Aug 29 '20

can it give gold?

1

u/[deleted] Aug 29 '20

of course!

1

u/vxpxl Aug 29 '20

This reminds me of that Tom Scott video.

1

u/[deleted] Aug 29 '20

That was my inspiration!

1

u/vxpxl Aug 29 '20

Good work

1

u/[deleted] Aug 29 '20

Thanks!

1

u/PapaDonut9 Aug 29 '20

Is there any way to get the number of awards in this api?

2

u/[deleted] Aug 29 '20

Im not sure... ill look into it

2

u/[deleted] Aug 29 '20

just made the award counter! hope people test it out wink wink ;)

1

u/PapaDonut9 Aug 29 '20

but this is way better, this has a lot of potential tbh

1

u/[deleted] Aug 29 '20

it is pretty good, but it cant blow up much more -- i posted it a day ago

1

u/sherpabrowsing Aug 28 '20

*134

edit: *135

1

u/[deleted] Aug 28 '20

this is going to go on forever isn’t it

→ More replies (1)

1

u/redtonicspear Aug 29 '20

Kinda stole someones post almost verbatum 😕

1

u/[deleted] Aug 29 '20

i didn’t steal it, i had the idea and acted on it. someone pointed it out, and i credited them for it.

1

u/Kalle_022 Aug 29 '20

it really makes me cry that Tom Scott's spirit is very much alive in programming communities.

(He's very much alive, don't worry)

1

u/[deleted] Aug 29 '20

:) Thank you!

2

u/[deleted] Aug 28 '20

That's pretty cool.

2

u/arbeit22 Aug 28 '20

holy shit this is awesome

2

u/EastBlessings Aug 29 '20

Oh, the Internets is staring right back at us!

2

u/sargeanthost Aug 29 '20

1.3k upvotes

1

u/cssmith2011cs Aug 28 '20

Hey! Y’all quit upvoting and then unclicking it so I can watch my upvote go up one and then down one.

1

u/[deleted] Aug 28 '20

nuts

1

u/[deleted] Aug 28 '20

Hi

1

u/kdawg_thetruth Aug 28 '20

Pretty awesome!

1

u/[deleted] Aug 28 '20

hello world

1

u/bashogaya Aug 28 '20

Test comment

1

u/[deleted] Aug 28 '20

145th!!!

1

u/Gaming_Friends Aug 28 '20

Yo this one's cool, well done!

1

u/justreading13 Aug 29 '20

Just trying

1

u/TheMemestUsernameFTW Aug 29 '20

This is very nice. Cool!

1

u/tony_saufcok Aug 29 '20

commenting to see the number go up

1

u/[deleted] Aug 29 '20

174 comments

1

u/[deleted] Aug 29 '20

Now its 175

1

u/[deleted] Aug 29 '20

126 (omments haha this is fun

1

u/[deleted] Aug 29 '20

Wow

1

u/KOking479 Aug 29 '20

Dang it actually works good job

1

u/ha-ha-ha_itsme Aug 29 '20

im going to comment only to see if this works

1

u/galian99 Aug 29 '20

And now?

1

u/Historica97 3.5, 3.6, 3.7, 3.8, 3.9, 3.10 Aug 29 '20

Let's see if it works

1

u/[deleted] Aug 29 '20

Hmmm

1

u/ChokituBR Aug 29 '20

I was trying to do something similar with a facebook post, sadly the final result I was able to make after 2 hours was very sketchy

1

u/universesrevinu Aug 29 '20

interesting...

1

u/[deleted] Aug 29 '20

Nice

1

u/remerdy1 Aug 29 '20

230th comment

1

u/misterlight re-learning after a 10 years stop Aug 29 '20

Nice

1

u/[deleted] Aug 29 '20

Poo

1

u/[deleted] Aug 29 '20

Poopy

1

u/JanStreams Aug 29 '20

No it is wrong is has 244 comments

1

u/[deleted] Aug 29 '20

Holy fuck, nice one

1

u/[deleted] Aug 29 '20

Nice

1

u/lexyp29 Aug 29 '20

test comment

1

u/[deleted] Aug 29 '20

print(fr'''lol''')

1

u/[deleted] Aug 29 '20

test

1

u/[deleted] Aug 29 '20

Now 299 😳

1

u/Anabolic_Horse_ Jan 28 '21

Inserting a comment to just see if it works