This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def update_location(bodies, time_step = 1): | |
| for target_body in bodies: | |
| target_body.location.x += target_body.velocity.x * time_step | |
| target_body.location.y += target_body.velocity.y * time_step | |
| target_body.location.z += target_body.velocity.z * time_step |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def compute_velocity(bodies, time_step = 1): | |
| for body_index, target_body in enumerate(bodies): | |
| acceleration = calculate_single_body_acceleration(bodies, body_index) | |
| target_body.velocity.x += acceleration.x * time_step | |
| target_body.velocity.y += acceleration.y * time_step | |
| target_body.velocity.z += acceleration.z * time_step |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calculate_single_body_acceleration(bodies, body_index): | |
| G_const = 6.67408e-11 #m3 kg-1 s-2 | |
| acceleration = point(0,0,0) | |
| target_body = bodies[body_index] | |
| for index, external_body in enumerate(bodies): | |
| if index != body_index: | |
| r = (target_body.location.x - external_body.location.x)**2 + (target_body.location.y - external_body.location.y)**2 + (target_body.location.z - external_body.location.z)**2 | |
| r = math.sqrt(r) | |
| tmp = G_const * external_body.mass / r**3 | |
| acceleration.x += tmp * (external_body.location.x - target_body.location.x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import praw | |
| import sys | |
| def get_subreddit_comments(reddit_agent, subreddit, comments_out = [], count = 100): | |
| try: | |
| sub = reddit_agent.get_subreddit(subreddit) | |
| comments_raw = sub.get_comments(sub, limit=count) | |
| comments_flat = praw.helpers.flatten_tree(comments_raw) | |
| for comment in comments_flat: | |
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import praw | |
| def get_subreddit_comments(reddit_agent, subreddit, comments_out = [], count = 100): | |
| try: | |
| sub = reddit_agent.get_subreddit(subreddit) | |
| comments_raw = sub.get_comments(sub, limit=count) | |
| comments_flat = praw.helpers.flatten_tree(comments_raw) | |
| for comment in comments_flat: | |
| try: | |
| if hasattr(comment, 'comments'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if __name__ == "__main__": | |
| client_id = 'your_client_id' | |
| client_secret = 'your_client_secret' | |
| reddit_agent = get_reddit_agent('custom name for app', client_id, client_secret) | |
| #list of canadian reddits to search | |
| canada_reddits = ['canada','alberta','britishcolumbia','Manitoba','NewBrunswickCanada', 'newfoundland', | |
| 'NovaScotia','nunavut','NWT','ontario','PEI', 'saskatchewan','Yukon'] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_sorry_and_word_count(comment_list, apologies = ['sorry', 'apologies']): | |
| sorry_count = 0 | |
| word_count = 0 | |
| for comment in comment_list: | |
| words = comment.split(' ') | |
| word_count += int(len(words)) | |
| for word in words: | |
| for apology in apologies: | |
| sorry_count += word.lower().count(apology) | |
| return sorry_count, word_count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_subreddit_comments(reddit_agent, subreddit, comments_out = [], count = 100): | |
| #surrounded by try catch in case API calls get exceed | |
| try: | |
| sub = reddit_agent.get_subreddit(subreddit) | |
| comments_raw = sub.get_comments(sub, limit=count) | |
| comments_flat = praw.helpers.flatten_tree(comments_raw) | |
| for comment in comments_flat: | |
| #try catch handles end of reply tree containing a null comment | |
| try: | |
| if hasattr(comment, 'comments'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_reddit_agent(user_agent, client_id, client_secret, redirect='http://127.0.0.1'): | |
| reddit_agent = praw.Reddit(user_agent = user_agent) | |
| reddit_agent.set_oauth_app_info(client_id = client_id, | |
| client_secret = client_secret, | |
| redirect_uri = redirect) | |
| return reddit_agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def read_messages(twitter_account, since = 0): | |
| mentions = tweepy.Cursor(twitter_account.mentions_timeline, since_id = str(since)).items() | |
| tweets = [] | |
| for tweet in tweets: | |
| tweets.append(tweet.text) | |
| if (tweet.id > since): | |
| since = tweet.id | |
| return {"messages":tweets, "since_id": since} |