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 getSentiment(df, measurement="compound"): | |
| """ | |
| Given a DF of tweets, analyzes the tweets and returns a new DF | |
| of sentiment scores based on the given measurement. | |
| Accepted sentiment measurements: ["pos", "neg", "neu", "compound"] | |
| """ | |
| # Sentiment Analyzer | |
| sia = SentimentIntensityAnalyzer() |
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 tweetByDay(start, end, df, search, limit=20): | |
| """ | |
| Runs the twint query everyday between the given dates and returns | |
| the total dataframe. | |
| """ | |
| # Finishing the recursive loop | |
| if start==end: | |
| # Removing any potential duplicates | |
| df = df.drop_duplicates(subset="id") | |
| print(len(df)) |
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 getTweets(search_term, until, limit=20): | |
| """ | |
| Configures Twint and returns a dataframe of tweets for a specific day. | |
| """ | |
| # Configuring Twint for search | |
| c = twint.Config() | |
| # The limit of tweets to retrieve | |
| c.Limit = limit |
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 makeBio(subscriber): | |
| """ | |
| Making a short or long bio depending their subscription status. | |
| """ | |
| if subscriber==True: | |
| # Randomizing bio length but skewed towards longer bios | |
| bio_len = random.choices([10,20], weights=(10,90), k=1)[0] | |
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 getEducation(dob): | |
| """ | |
| Assigns an education level based on the given date of birth | |
| """ | |
| # Current date | |
| now = datetime.datetime.now() | |
| # Date of birth | |
| dob = datetime.datetime.strptime(dob, "%Y-%m-%d") | |
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 random_dob(start, end, n): | |
| """ | |
| Generating a list of a set number of timestamps | |
| """ | |
| # The timestamp format | |
| frmt = "%Y-%m-%d" | |
| # Formatting the two time periods | |
| stime = datetime.datetime.strptime(start, frmt) |
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 randomtimes(start, end, n): | |
| """ | |
| Generates random time stamps based on a given amount between two time periods. | |
| """ | |
| # The timestamp format | |
| frmt = "%Y-%m-%d %H:%M:%S" | |
| # Formatting the two time periods | |
| stime = datetime.datetime.strptime(start, frmt) | |
| etime = datetime.datetime.strptime(end, frmt) |
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 emailGen(name, duplicateFound=False): | |
| """ | |
| Generates a random email address based on the given name. | |
| Adds a number at the end if a duplicate address was found. | |
| """ | |
| # Fake domain name to use | |
| dom = "@fakemail.com" | |
| # Lowercasing and splitting | |
| name = name.lower().split(" ") |
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 sendMyEmail(sender, recipient, subject, content): | |
| """ | |
| Takes in email details to send an email to whoever. | |
| """ | |
| # Sendgrid client | |
| email = Mail( | |
| from_email=sender, | |
| to_emails=recipient, | |
| subject=subject, | |
| html_content=content |
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
| # Sending a different email with 3 different greetings | |
| for i in ["Hey", "Hi", "Hello"]: | |
| # Setting the variables to dynamically change | |
| sender = "[email protected]" | |
| recipient = "[email protected]" | |
| subject = f"{i} Check Out My Email!" |