Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import websocket
- import config
- import praw
- import json
- import time
- import datetime
- import getpass
- import pytz
- FIRST_MIDNIGHT = 1520917200 - 3600
- #FIRST_MIDNIGHT = 1519448403
- DAY = 24 * 60 * 60
- cur_update = 'LiveUpdate_0036af64-2673-11e8-b848-0e79ce9b2ccc'
- def bot_login():
- print("Logging In...")
- login = praw.Reddit(username = config.username,
- password = config.password,
- client_id = config.client_id,
- client_secret = config.client_secret,
- user_agent = "Copies messages from livecounting to a separate thread for later reading")
- return login
- def thread_about(thread):
- #Returns the live thread's about.json data, including the WebSocket (wss) URL, sidebar (resources) contents, etc.
- # Get websocket_url from about.json
- response = login.request(
- method = 'GET',
- path = 'live/' + thread + '/about',
- params = { 'raw_json': 1 }
- );
- # Return websocket_url from response
- return response;
- def get_old_updates(cur_update):
- return login.request(
- method = 'GET',
- path = 'live/' + config.thread,
- params = {
- 'before' : cur_update,
- 'limit' : '100'
- }
- );
- def find_next_midnight(target, cur_update):
- updates = 0 # Because python is gross and I don't know a better way to give this scope here
- while True:
- updates = get_old_updates(cur_update)['data']['children']
- #print(str(updates[0]['data']['created_utc']))
- if updates[0]['data']['created_utc'] > target:
- break
- cur_update = updates[0]['data']['name']
- for i in range(len(updates)):
- if updates[i]['data']['created_utc'] < target:
- return (updates[i], updates[i-1], cur_update)
- config.password = getpass.getpass("Password:")
- login = bot_login()
- current_midnight = FIRST_MIDNIGHT
- for i in range(22):
- target_midnight = current_midnight + DAY
- #print("Target: " + str(target_midnight))
- (last, first, cur_update) = find_next_midnight(target_midnight, cur_update)
- lasttime = datetime.datetime.fromtimestamp(last['data']['created_utc'])
- firsttime = datetime.datetime.fromtimestamp(first['data']['created_utc'])
- print("Last update of " + lasttime.strftime('%Y-%m-%d') + " at " + lasttime.strftime('%H:%M:%S') + ": " + last['data']['name'])
- print("First update of " + firsttime.strftime('%Y-%m-%d') + " at " + firsttime.strftime('%H:%M:%S') + ": " + first['data']['name'])
- current_midnight = target_midnight
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement