Are you sure you want to delete this access key?
cd streamlit/app
python start.py
cd fastapi/app
python start.py
accounts:
tweets:
# "AGIR-E": "centre-droit", # https://fr.wikipedia.org/wiki/Groupe_Agir_ensemble
# "DEM": "centre", # https://fr.wikipedia.org/wiki/Mouvement_d%C3%A9mocrate_(France)
# "DLF": "droite-plus", # https://fr.wikipedia.org/wiki/Debout_la_France
# "EDS": "centre-gauche", # https://fr.wikipedia.org/wiki/Groupe_%C3%89cologie_d%C3%A9mocratie_solidarit%C3%A9
# "FI": "gauche-plus", # https://fr.wikipedia.org/wiki/La_France_insoumise
# "GDR": "gauche-plus", # https://fr.wikipedia.org/wiki/Groupe_de_la_Gauche_d%C3%A9mocrate_et_r%C3%A9publicaine
# "GE": "centre-gauche", # https://fr.wikipedia.org/wiki/G%C3%A9n%C3%A9ration_%C3%A9cologie
# "LAREM": "centre", # https://fr.wikipedia.org/wiki/La_R%C3%A9publique_en_marche
# "LDS": "droite-plus", # https://fr.wikipedia.org/wiki/Ligue_du_Sud_(France)
# "LND": "gauche", # https://fr.wikipedia.org/wiki/Les_Nouveaux_D%C3%A9mocrates
# "LR": "droite", # https://fr.wikipedia.org/wiki/Les_R%C3%A9publicains
# "LT": "centre", # https://fr.wikipedia.org/wiki/Groupe_Libert%C3%A9s_et_territoires
# "RN": "droite-plus", # https://fr.wikipedia.org/wiki/Rassemblement_national
# "SOC": "gauche", # https://fr.wikipedia.org/wiki/Groupe_socialiste_(Assembl%C3%A9e_nationale)
# "UDI_I": "centre-droit", # https://fr.wikipedia.org/wiki/Union_des_d%C3%A9mocrates_et_ind%C3%A9pendants
def get_target(group):
'''
Takes the political group as an argument
Returns 'droite' or 'gauche'
Else returns 'centre' e.g. if it is a group of the center
'''
target_dict = {
"droite":["AGIR-E", "DLF", "LDS", "LR", "RN", "UDI_I"],
"gauche":["EDS", "FI", "GDR", "GE", "LND", "SOC"],
}
if group in target_dict["droite"]:
return "droite"
elif group in target_dict["gauche"]:
return "gauche"
else:
return "centre"
database connection
uri = "mongodb+srv://politweet:<password>@cluster0.0rn9i.mongodb.net/politweet?retryWrites=true&w=majority" # replace <password>
client = MongoClient(uri)
db = client.politweet
get all tweets with all fields
cursor = db.tweets.find() #cursor
tweets = list(db.tweets.find()) #fetchall
get all tweets except retweeted and quoted ones, filter the result to only get content and group fields
tweets = list(db.tweets.find({"retweetedTweet":False, "quotedTweet":False}, {"_id":0, "content":1, "group":1}))
convert to a dataframe:
df = pd.DataFrame(tweets) # you can use cursor instead too
save to json and load as a dataframe
with open('data.json', 'w') as f:
json.dump(jsonable_encoder(tweets), f)
df = pd.read_json('data.json')
join with account collection to get extra fields, here we add followersCount field:
pipeline = [{'$lookup':
{'from' : 'accounts',
'localField' : 'account_id',
'foreignField' : '_id',
'as' : 'account'}},
{'$unwind': '$account'},
{'$project': {'_id':0, 'content':1, 'followersCount': '$account.followersCount'}}]
cursor = db.tweets.aggregate(pipeline)
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?