1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 06:24:19 +00:00

Aggiunto il salvataggio di immagini se presenti nel tweet salvato, e il salvataggio della data e ora al quale il tweet e' stato postato

This commit is contained in:
g.minoccari 2021-05-22 17:00:22 +02:00
parent efe05351a2
commit 6f88f3f5af

View file

@ -53,7 +53,7 @@ def search_repo_conditions(repository_id):
if ConditionType.coordinates in conditions_type.keys():
if evaluation_mode == ConditionMode.all_and:
if len(conditions_type[ConditionType.coordinates]) == 1:
coordinates_tweet = conditions_type[ConditionType.coordinates][0].split()
coordinates_tweet = conditions_type[ConditionType.coordinates][0].content.split()
coordinates_string = coordinates_tweet[2] + "," + coordinates_tweet[3] + "," + str(float(coordinates_tweet[1])/1000) + "km"
else:
return None
@ -64,11 +64,19 @@ def search_repo_conditions(repository_id):
print(coordinates_string)
for tweet in tw.Cursor(method=api.search, q="", geocode=coordinates_string).items(10):
if not Tweet.query.filter_by(snowflake=str(tweet.id)).all():
image_url_list = ''
if 'media' in tweet.entities.keys():
for url in tweet.entities['media']:
image_url_list += (url['media_url_https'] + '|')
image_url_list = image_url_list[:-1]
else:
image_url_list = None
tweetDB = Tweet(snowflake=tweet.id, content=tweet.text,
location=tweet.geo['coordinates'] if tweet.geo is not None else None,
place=tweet.place.full_name if tweet.place is not None else None,
insert_time=str(datetime.now()),
poster=tweet.author.screen_name)
poster=tweet.author.screen_name, post_time=str(tweet.created_at), image_url=image_url_list)
ext.session.add(tweetDB)
ext.session.commit()
if not Contains.query.filter_by(snowflake=str(tweet.id), cid=condition_content.id).all():
@ -94,30 +102,39 @@ def search_repo_conditions(repository_id):
if queryString != "":
for tweet in tw.Cursor(method=api.search, q=queryString).items(10):
tweetsFound.append(tweet)
print(tweet.user.name + ' : ' + tweet.text + ' : ' + tweet.geo)
print(tweet.user.name + ' : ' + tweet.text + ' : ' + tweet.geo if tweet.geo is not None else '')
elif evaluation_mode == ConditionMode.all_and:
for tweet in tw.Cursor(method=api.search, q=queryString, geocode=coordinates_string).items(10):
tweetsFound.append(tweet)
print(tweet.user.name + ' : ' + tweet.text + ' : ' + str(tweet.geo))
for tweet in tweetsFound:
if not Tweet.query.filter_by(snowflake=str(tweet.id)).all():
image_url_list = ''
if 'media' in tweet.entities.keys():
for url in tweet.entities['media']:
image_url_list += (url['media_url_https'] + '|')
image_url_list = image_url_list[:-1]
else:
image_url_list = None
tweetDB = Tweet(snowflake=tweet.id, content=tweet.text,
location=tweet.geo['coordinates'] if tweet.geo is not None else None,
place=tweet.place.full_name if tweet.place is not None else None,
insert_time=str(datetime.now()),
poster=tweet.author.screen_name)
poster=tweet.author.screen_name, post_time=str(tweet.created_at), image_url=image_url_list)
ext.session.add(tweetDB)
ext.session.commit()
if evaluation_mode == ConditionMode.all_or:
if ConditionType.hashtag in conditions_type.keys():
for condition_content in conditions_type[ConditionType.hashtag]:
if condition_content.content in [hashtag['text'] for hashtag in tweet.entities['hashtags']]:
if not Contains.query.filter_by(snowflake=str(tweet.id), cid=condition_content.id).all():
condition_associated = Contains(cid=condition_content.id, snowflake=tweet.id)
ext.session.add(condition_associated)
ext.session.commit()
if ConditionType.user in conditions_type.keys():
for condition_content in conditions_type[ConditionType.user]:
if condition_content.content == tweet.author.screen_name:
if not Contains.query.filter_by(snowflake=str(tweet.id), cid=condition_content.id).all():
condition_associated = Contains(cid=condition_content.id, snowflake=tweet.id)
ext.session.add(condition_associated)
ext.session.commit()
@ -127,17 +144,19 @@ def search_repo_conditions(repository_id):
condition_date_time = datetime.fromisoformat(condition_content.content[2:])
if condition_content.content[0] == '<':
if tweet.created_at < condition_date_time:
if not Contains.query.filter_by(snowflake=str(tweet.id), cid=condition_content.id).all():
condition_associated = Contains(cid=condition_content.id, snowflake=tweet.id)
ext.session.add(condition_associated)
ext.session.commit()
elif condition_content.content[0] == '>':
if tweet.created_at > condition_date_time:
if not Contains.query.filter_by(snowflake=str(tweet.id), cid=condition_content.id).all():
condition_associated = Contains(cid=condition_content.id, snowflake=tweet.id)
ext.session.add(condition_associated)
ext.session.commit()
elif evaluation_mode == ConditionMode.all_and:
for condition in conditions:
if Contains.query.filter_by(snowflake=str(tweet.id), cid=condition.id).all():
if not Contains.query.filter_by(snowflake=str(tweet.id), cid=condition.id).all():
condition_associated = Contains(cid=condition.id, snowflake=tweet.id)
ext.session.add(condition_associated)
ext.session.commit()