def parse_subreddits(): session = Session() reddit = praw.Reddit(client_id='Q8FkH2LSqlFeqg', client_secret='3Fe1o1_LTgp53yijN2JU9BOqX6U', user_agent='script:midterm_data:1.0 (by /u/Luxxee)', requestor_kwargs={'session': session}, username='******', password='******') reddit.read_only = True # Get the ID of the folder made to store today's data folder_for_day = create_folder( str(datetime.today()), '1ab8g1EWSS1PcLibWwD83sXLGtzQds4IJ') # Establish Subreddits subreddits = ['BlueMidterm2018', 'politics', 'massachusettspolitics', 'mainepolitics', 'vermontpolitics'] # For every subreddit in the list for sub in subreddits: # Get the data topics_dictionary = get_posts_for_day(reddit.subreddit(sub)) # Format it topics_data = pd.DataFrame(topics_dictionary) # Export to CSV name = sub + str(datetime.combine(datetime.today(), time.min)) + '.csv' topics_data.to_csv(name, index=False) # Upload to drive upload_sheet(name, folder_for_day)
def main(): session = Session() reddit = praw.Reddit(client_id='Q8FkH2LSqlFeqg', client_secret='3Fe1o1_LTgp53yijN2JU9BOqX6U', user_agent='script:midterm_data:1.0 (by /u/Luxxee)', requestor_kwargs={'session': session}, username='******', password='******') reddit.read_only = True # Get the ID of the folder made to store today's data folder_for_day = create_folder(str(datetime.today()), '1ab8g1EWSS1PcLibWwD83sXLGtzQds4IJ') parse_subreddits()
client_secret='3Fe1o1_LTgp53yijN2JU9BOqX6U', user_agent='script:midterm_data:1.0 (by /u/Luxxee)', requestor_kwargs={'session': session}, username='******', password='******') reddit.read_only = True # Establish Subreddits subreddits = [ 'BlueMidterm2018', 'politics', 'massachusettspolitics', 'mainepolitics', 'vermontpolitics' ] # Get the ID of the folder made to store today's data folder_for_day = create_folder(str(datetime.today()), '1ab8g1EWSS1PcLibWwD83sXLGtzQds4IJ') # For determining if a post from the subreddit is within the desired range def is_yesterday(timestamp): midnight = datetime.combine(datetime.today(), time.min) yesterday_midnight = (midnight - timedelta(days=1)) return yesterday_midnight.timestamp() <= timestamp < midnight.timestamp() # Gets the posts for the day in the given subreddit and returns the data in a dictionary def get_posts_for_day(subreddit): topics_dictionary = {
def test_create_folder(upload, session, token): folder_path = '/' + 'test_folder_' + get_unique_string() assert upload.create_folder(session, folder=folder_path, csrf=token), 'folder creation failed' assert upload.remove_object(session, obj=folder_path, csrf=token), 'folder removal failed'