r/Python • u/[deleted] • 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!
105
u/Config_Crawler Aug 28 '20
This is pretty cool.
81
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
138
Aug 28 '20
Ok
59
Aug 28 '20
i hope this works lol
30
Aug 28 '20
Wow looks like it is Edit: it says 0 upvotes but I upvoted
46
Aug 28 '20 edited Aug 28 '20
it updates every minute
Edit: Now it updates every second11
u/dgriffith Aug 29 '20
There's no rate limiting in Reddit's API?
→ More replies (1)4
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)25
5
21
8
u/SpiritualCup Aug 28 '20
How do you get the amount of downvotes using PRAW??? Couldn’t figure it out
13
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)4
3
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
7
u/Blobtoe Aug 28 '20
Must... Keep... The 69 upvotes.
3
Aug 28 '20
so sad.. it went away
→ More replies (1)3
2
2
u/Furkan_122 Aug 28 '20
How do you host this script?
2
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
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
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
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
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
2
11
7
7
1
1
1
1
Aug 28 '20
Holy cow! That's really, really cool! I upvoted and refreshed and got to see it change. Great job.
1
1
1
1
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
1
Aug 28 '20
Yo somebody edited the main.py file like 12 seconds ago
1
1
u/412gage Aug 28 '20
I’m literally going back and forth upvoting and downvoting to see it work haha
1
1
1
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
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
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
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
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
1
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
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
1
u/Bio42 Aug 29 '20
Inaccurate for mobile
1
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
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
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
Aug 29 '20
lol i should hope not..
1
u/-_-qarmah-_- Aug 29 '20
You're making way too many requests.
2
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
1
u/v3ctorns1mon Aug 29 '20
Hey u/TAPTITANS3, How are you hosting the source code? Like which platform are you using?
2
Aug 29 '20
I am currently using Heroku It is a free hosting app and it works quite well!
0
1
1
1
1
u/PapaDonut9 Aug 29 '20
Is there any way to get the number of awards in this api?
2
2
Aug 29 '20
just made the award counter! hope people test it out wink wink ;)
1
1
1
u/redtonicspear Aug 29 '20
Kinda stole someones post almost verbatum 😕
1
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
2
2
2
2
2
2
1
1
1
1
1
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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
185
u/[deleted] Aug 28 '20 edited Aug 29 '20
Or does it? *Votes, reloads, unvotes, reloads