Skip to content

Instantly share code, notes, and snippets.

View marcosan93's full-sized avatar

Marco Santos marcosan93

View GitHub Profile
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()
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))
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
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]
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")
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)
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)
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(" ")
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
# 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!"