1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

Merge branch 'main' of zero.ryg.one:nest/g2-progetto

This commit is contained in:
FlaviaC-uni 2021-05-28 17:29:30 +02:00
commit 56939afb3b
16 changed files with 118 additions and 24 deletions

Binary file not shown.

View file

@ -2,3 +2,4 @@
==================================== ====================================
.. automodule:: nest_crawler .. automodule:: nest_crawler
:imported-members:

View file

@ -598,6 +598,11 @@ for example, any mapped columns or relationships.</p>
<code class="sig-name descname"><span class="pre">is_active</span></code><a class="headerlink" href="#nest_backend.database.tables.Repository.is_active" title="Link a questa definizione"></a></dt> <code class="sig-name descname"><span class="pre">is_active</span></code><a class="headerlink" href="#nest_backend.database.tables.Repository.is_active" title="Link a questa definizione"></a></dt>
<dd></dd></dl> <dd></dd></dl>
<dl class="py attribute">
<dt id="nest_backend.database.tables.Repository.is_deleted">
<code class="sig-name descname"><span class="pre">is_deleted</span></code><a class="headerlink" href="#nest_backend.database.tables.Repository.is_deleted" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
<dl class="py attribute"> <dl class="py attribute">
<dt id="nest_backend.database.tables.Repository.evaluation_mode"> <dt id="nest_backend.database.tables.Repository.evaluation_mode">
<code class="sig-name descname"><span class="pre">evaluation_mode</span></code><a class="headerlink" href="#nest_backend.database.tables.Repository.evaluation_mode" title="Link a questa definizione"></a></dt> <code class="sig-name descname"><span class="pre">evaluation_mode</span></code><a class="headerlink" href="#nest_backend.database.tables.Repository.evaluation_mode" title="Link a questa definizione"></a></dt>

View file

@ -178,6 +178,41 @@
<div class="section" id="module-nest_crawler"> <div class="section" id="module-nest_crawler">
<span id="nest-crawler-crawler-in-python"></span><h1><code class="docutils literal notranslate"><span class="pre">nest_crawler</span></code> - Crawler in Python<a class="headerlink" href="#module-nest_crawler" title="Link a questa intestazione"></a></h1> <span id="nest-crawler-crawler-in-python"></span><h1><code class="docutils literal notranslate"><span class="pre">nest_crawler</span></code> - Crawler in Python<a class="headerlink" href="#module-nest_crawler" title="Link a questa intestazione"></a></h1>
<dl class="py function">
<dt id="nest_crawler.associate_condition_tweet">
<code class="sig-prename descclassname"><span class="pre">nest_crawler.</span></code><code class="sig-name descname"><span class="pre">associate_condition_tweet</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">conditions_type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tweet</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nest_crawler.associate_condition_tweet" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="nest_crawler.authenticate">
<code class="sig-prename descclassname"><span class="pre">nest_crawler.</span></code><code class="sig-name descname"><span class="pre">authenticate</span></code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#nest_crawler.authenticate" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="nest_crawler.is_coordinate_inside_bounding_box">
<code class="sig-prename descclassname"><span class="pre">nest_crawler.</span></code><code class="sig-name descname"><span class="pre">is_coordinate_inside_bounding_box</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">latitude</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">longitude</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">radius</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tweet_latitude</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tweet_longitude</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nest_crawler.is_coordinate_inside_bounding_box" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="nest_crawler.is_repo_alert_triggered">
<code class="sig-prename descclassname"><span class="pre">nest_crawler.</span></code><code class="sig-name descname"><span class="pre">is_repo_alert_triggered</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">repository_id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nest_crawler.is_repo_alert_triggered" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="nest_crawler.search_repo_conditions">
<code class="sig-prename descclassname"><span class="pre">nest_crawler.</span></code><code class="sig-name descname"><span class="pre">search_repo_conditions</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">repository_id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nest_crawler.search_repo_conditions" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="nest_crawler.send_notification_email">
<code class="sig-prename descclassname"><span class="pre">nest_crawler.</span></code><code class="sig-name descname"><span class="pre">send_notification_email</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">alert</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nest_crawler.send_notification_email" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
<dl class="py function">
<dt id="nest_crawler.send_notification_tweet">
<code class="sig-prename descclassname"><span class="pre">nest_crawler.</span></code><code class="sig-name descname"><span class="pre">send_notification_tweet</span></code><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">alert</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#nest_crawler.send_notification_tweet" title="Link a questa definizione"></a></dt>
<dd></dd></dl>
</div> </div>

View file

@ -256,8 +256,14 @@
</li> </li>
<li><a href="code/backend/index.html#nest_backend.database.tables.OperationType.assign">assign (nest_backend.database.tables.OperationType attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.OperationType.assign">assign (nest_backend.database.tables.OperationType attributo)</a>
</li> </li>
<li><a href="code/backend/index.html#nest_backend.gestione.authenticate">authenticate() (nel modulo nest_backend.gestione)</a> <li><a href="code/crawler/index.html#nest_crawler.associate_condition_tweet">associate_condition_tweet() (nel modulo nest_crawler)</a>
</li> </li>
<li><a href="code/backend/index.html#nest_backend.gestione.authenticate">authenticate() (nel modulo nest_backend.gestione)</a>
<ul>
<li><a href="code/crawler/index.html#nest_crawler.authenticate">(nel modulo nest_crawler)</a>
</li>
</ul></li>
<li><a href="code/backend/index.html#nest_backend.database.tables.Authorization">Authorization (classe in nest_backend.database.tables)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Authorization">Authorization (classe in nest_backend.database.tables)</a>
</li> </li>
<li><a href="code/backend/index.html#nest_backend.database.tables.Repository.authorizations">authorizations (nest_backend.database.tables.Repository attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Repository.authorizations">authorizations (nest_backend.database.tables.Repository attributo)</a>
@ -380,15 +386,21 @@
<li><a href="code/backend/index.html#nest_backend.database.tables.Repository.id">(nest_backend.database.tables.Repository attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Repository.id">(nest_backend.database.tables.Repository attributo)</a>
</li> </li>
</ul></li> </ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="code/backend/index.html#nest_backend.gestione.identity">identity() (nel modulo nest_backend.gestione)</a> <li><a href="code/backend/index.html#nest_backend.gestione.identity">identity() (nel modulo nest_backend.gestione)</a>
</li> </li>
<li><a href="code/backend/index.html#nest_backend.database.tables.Tweet.image_url">image_url (nest_backend.database.tables.Tweet attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Tweet.image_url">image_url (nest_backend.database.tables.Tweet attributo)</a>
</li> </li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="code/backend/index.html#nest_backend.database.tables.Tweet.insert_time">insert_time (nest_backend.database.tables.Tweet attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Tweet.insert_time">insert_time (nest_backend.database.tables.Tweet attributo)</a>
</li> </li>
<li><a href="code/backend/index.html#nest_backend.database.tables.Repository.is_active">is_active (nest_backend.database.tables.Repository attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Repository.is_active">is_active (nest_backend.database.tables.Repository attributo)</a>
</li>
<li><a href="code/crawler/index.html#nest_crawler.is_coordinate_inside_bounding_box">is_coordinate_inside_bounding_box() (nel modulo nest_crawler)</a>
</li>
<li><a href="code/backend/index.html#nest_backend.database.tables.Repository.is_deleted">is_deleted (nest_backend.database.tables.Repository attributo)</a>
</li>
<li><a href="code/crawler/index.html#nest_crawler.is_repo_alert_triggered">is_repo_alert_triggered() (nel modulo nest_crawler)</a>
</li> </li>
<li><a href="code/backend/index.html#nest_backend.database.tables.User.isAdmin">isAdmin (nest_backend.database.tables.User attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.User.isAdmin">isAdmin (nest_backend.database.tables.User attributo)</a>
</li> </li>
@ -586,6 +598,14 @@
<h2 id="S">S</h2> <h2 id="S">S</h2>
<table style="width: 100%" class="indextable genindextable"><tr> <table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="code/crawler/index.html#nest_crawler.search_repo_conditions">search_repo_conditions() (nel modulo nest_crawler)</a>
</li>
<li><a href="code/crawler/index.html#nest_crawler.send_notification_email">send_notification_email() (nel modulo nest_crawler)</a>
</li>
<li><a href="code/crawler/index.html#nest_crawler.send_notification_tweet">send_notification_tweet() (nel modulo nest_crawler)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul> <td style="width: 33%; vertical-align: top;"><ul>
<li><a href="code/backend/index.html#nest_backend.database.tables.Composed.snowflake">snowflake (nest_backend.database.tables.Composed attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Composed.snowflake">snowflake (nest_backend.database.tables.Composed attributo)</a>
@ -595,8 +615,6 @@
<li><a href="code/backend/index.html#nest_backend.database.tables.Tweet.snowflake">(nest_backend.database.tables.Tweet attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Tweet.snowflake">(nest_backend.database.tables.Tweet attributo)</a>
</li> </li>
</ul></li> </ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="code/backend/index.html#nest_backend.database.tables.Repository.start">start (nest_backend.database.tables.Repository attributo)</a> <li><a href="code/backend/index.html#nest_backend.database.tables.Repository.start">start (nest_backend.database.tables.Repository attributo)</a>
</li> </li>
</ul></td> </ul></td>

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -2,3 +2,4 @@
==================================== ====================================
.. automodule:: nest_crawler .. automodule:: nest_crawler
:imported-members:

View file

@ -33,9 +33,16 @@ Lorenzo Balugani - DB & Backend Developer
| Data | Durata | Attività | | Data | Durata | Attività |
|-------|--------|----------| |-------|--------|----------|
| | | | |17/5 |4h |Bugfixing, supporto alla localizzazione degli errori |
|18/5|2.0h|Bugfixing|
|20/5|3.0h|API autorizzazioni, refactoring|
|21/5|2.0h|Gestione tweet, rappresentazione tweet|
|24/5|2.0h|Bugfixing|
|25/5|4.0h|Docs, refactoring|
|27/5|3.0h|Bugfixing|
|28/5|6.0h|Bugfixing
|-------|--------| |-------|--------|
|totale| __._h | |totale| 22.0h |
Stefano Pigozzi - Sysadmin & Frontend Developer Stefano Pigozzi - Sysadmin & Frontend Developer

View file

@ -5,13 +5,13 @@ from nest_backend.gestione import *
import datetime import datetime
from flask_cors import cross_origin from flask_cors import cross_origin
from nest_backend.errors import * from nest_backend.errors import *
import nest_backend.app
from nest_crawler.repo_search import search_repo_conditions from nest_crawler.repo_search import search_repo_conditions
import threading import threading
def tweet_importer(rid): def tweet_importer(rid):
import nest_backend.app
with nest_backend.app.app.app_context(): with nest_backend.app.app.app_context():
search_repo_conditions(rid) search_repo_conditions(rid)

View file

@ -1 +1,4 @@
from .alert_trigger import *
from .associate_condition_tweet import *
from .authentication import *
from .repo_search import *

View file

@ -1,7 +1,7 @@
from nest_backend.database import * from nest_backend.database import *
from nest_backend.app import app, extension_sqlalchemy from nest_backend.app import app
from nest_crawler.repo_search import search_repo_conditions from .repo_search import search_repo_conditions
from alert_trigger import is_repo_alert_triggered from .alert_trigger import is_repo_alert_triggered
ext.init_app(app=app) ext.init_app(app=app)
@ -12,8 +12,7 @@ def search_all_repo():
search_repo_conditions(repo_id) search_repo_conditions(repo_id)
is_repo_alert_triggered(repo_id) is_repo_alert_triggered(repo_id)
if __name__ == "__main__": if __name__ == "__main__":
with app.app_context(): with app.app_context():
search_all_repo() search_all_repo()

View file

@ -1,8 +1,9 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from nest_backend.database import * from nest_backend.database import *
from authentication import authenticate from .authentication import authenticate
import smtplib import smtplib
def is_repo_alert_triggered(repository_id): def is_repo_alert_triggered(repository_id):
repo = Repository.query.filter_by(id=repository_id).first() repo = Repository.query.filter_by(id=repository_id).first()
if repo is None: if repo is None:
@ -56,6 +57,7 @@ def send_notification_email(alert):
if smtpObj is not None: if smtpObj is not None:
smtpObj.close() smtpObj.close()
def send_notification_tweet(alert): def send_notification_tweet(alert):
api = authenticate() api = authenticate()
conditions_string = '' conditions_string = ''
@ -65,3 +67,9 @@ def send_notification_tweet(alert):
print(conditions_string) print(conditions_string)
api.update_status(f"L'alert {alert.name} è stato attivato! C'è stato un incremento di popolarità negli argomenti di ricerca {conditions_string}") api.update_status(f"L'alert {alert.name} è stato attivato! C'è stato un incremento di popolarità negli argomenti di ricerca {conditions_string}")
__all__ = (
"is_repo_alert_triggered",
"send_notification_email",
"send_notification_tweet",
)

View file

@ -50,3 +50,9 @@ def is_coordinate_inside_bounding_box(latitude, longitude, radius, tweet_latitud
dLongitude = dLatitude * cos(radians(latitude)) dLongitude = dLatitude * cos(radians(latitude))
if (latitude - dLatitude < tweet_latitude < latitude+dLatitude) and (longitude-dLongitude < tweet_longitude < longitude+dLongitude): if (latitude - dLatitude < tweet_latitude < latitude+dLatitude) and (longitude-dLongitude < tweet_longitude < longitude+dLongitude):
return True return True
__all__ = (
"associate_condition_tweet",
"is_coordinate_inside_bounding_box",
)

View file

@ -1,14 +1,20 @@
import tweepy as tw import tweepy as tw
import os
def authenticate(): def authenticate():
c_k = "GEhtSyP9e98mzFeiOCSW0lvQX" c_k = os.getenv('C_K')
c_s = "438cmYrl5xqaX2W7I2Bf5A9nF1pN5VtM9f77WYQnAXg1BwKJ27" c_s = os.getenv('C_S')
a_t = "1380217745732689921-IW3U1JlxhnQeGBUrnHZ2nxbxhksXUZ" a_t = os.getenv('A_T')
a_t_s = "EUoYNoj72rb2q00tUIW8eTcLJAhUAYPstZlV78W9cPpEJ" a_t_s = os.getenv('A_T_S')
auth = tw.OAuthHandler(c_k, c_s) auth = tw.OAuthHandler(c_k, c_s)
auth.set_access_token(a_t, a_t_s) auth.set_access_token(a_t, a_t_s)
api = tw.API(auth, wait_on_rate_limit=True) api = tw.API(auth, wait_on_rate_limit=True)
# client = tw.Client(b_t, c_k, c_s, a_t, a_t_s, wait_on_rate_limit=True); # client = tw.Client(b_t, c_k, c_s, a_t, a_t_s, wait_on_rate_limit=True);
return api return api
__all__ = (
"authenticate",
)

View file

@ -1,8 +1,8 @@
from nest_backend.database import * from nest_backend.database import *
import nest_crawler.authentication as authentication from . import authentication
from datetime import datetime, timedelta from datetime import datetime
import tweepy as tw import tweepy as tw
from nest_crawler.associate_condition_tweet import associate_condition_tweet from .associate_condition_tweet import associate_condition_tweet
def search_repo_conditions(repository_id): def search_repo_conditions(repository_id):
@ -142,3 +142,8 @@ def search_repo_conditions(repository_id):
ext.session.add(composed) ext.session.add(composed)
ext.session.commit() ext.session.commit()
print(f"Done searching tweets from repo: {repo.name}") print(f"Done searching tweets from repo: {repo.name}")
__all__ = (
"search_repo_conditions",
)