• API
• FAQ
• Tools
• Archive
daily pastebin goal
83%
SHARE
TWEET

# Untitled

a guest Dec 11th, 2017 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/bin/python
2.
3. import time
4. import random as r
5. from getpass import getpass
6.
7. import praw
8.
9.
10. ORIGINAL_PRICE = 10.00
11. MIN_PRICE = 5.00
12. MAX_PRICE = 15.00
13. STEP_PRICE = 0.01
14.
15. TARGET_POST_ID="7ieoji"
16.
17. # '{first}' will be replaced with the first price and '{second}' with the second
18. POST_TEXT = "...for \$10.00 worth of Bitcoin currency.\n\nDad: \${first}? What do you need \${second} for?"
19.
20. # Update interval in seconds
21. # Multiply by 60 for minutes, 60*60 for hours, etc.
22. # Probably shouldn't set this too low - Reddit might yell at both you and me
23. UPDATE_INTERVAL=15*60
24.
25. USERNAME = "cubesnack" # Do not include the '/u/'
27.
28. CLIENT_ID=''
29. CLIENT_SECRET=''
30. USER_AGENT = "python:bitcoin_replacement_bot:0.1 (by /u/skylos2000)"
31.
32. reddit = praw.Reddit(client_id=CLIENT_ID, client_secret=CLIENT_SECRET,
33.                     user_agent=USER_AGENT,
35. me = reddit.user.me()
36.
37.
38. def get_random_price(minimum=MIN_PRICE, maximum=MAX_PRICE):
39.     # I'm too lazy to figure out how to generate a random decimal so I'll just do this:
40.
41.     # The prices are multiplied by 100 to convert dollars to cents then converted back
42.     # to dollars by divinding by 100
43.     # This won't work for fractions of cents but this is for imaginary internet points
44.     # so I don't really care how fragile it is.
45.     return r.randrange(minimum * 100, maximum * 100, STEP_PRICE * 100) / 100
46.
47.
48. def get_price_pair():
49.     # Generate prices
50.     first = get_random_price(maximum=ORIGINAL_PRICE)
51.     second = get_random_price(minimum=first)
52.
53.     # If they are equal, regenerate `second` and check again for the (literally, I think) one in a million
54.     # chance that they are equal a second time
55.     # `trial` keeps track of how many times they are equivalent
56.     trial = 1
57.     while first == second:
58.         print(f"Prices were equal for the {trial} time. Regenerating the second price.")
59.         second = get_random_price(minimum=first)
60.
61.     # Return a pair of the prices
62.     return first, second
63.
64.
65. def update_reddit_post(first_price, second_price, target):
66.     target.edit(POST_TEXT.format(first=first_price, second=second_price))
67.
68. def main():
69.     if UPDATE_INTERVAL < 60:
70.         # Just to be sure its not accidently set to low
71.         raise ValueError("UPDATE_INTERVAL must be longer than 60 seconds. You set it to {UPDATE_INTERVAL}.")
72.
73.     while True:
74.         target_post = reddit.submission(id=TARGET_POST_ID)
75.         update_reddit_post(*get_price_pair(), target_post)
76.         time.sleep(UPDATE_INTERVAL)
77.
78. if __name__ == "__main__":
79.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top