-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
51 lines (40 loc) · 1.58 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# PI3 backend for scanning social media profile similarities
import os
from flask import Flask, request, jsonify, Response
from flask_cors import CORS, cross_origin
import lib.db
import lib.scanner.twitter.twitter as twit
import lib.scanner.twitter.comparitor as comparator
# Initialize Flask app
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
# Init firestore connection:
db_conn = lib.db.create_connection()
user_ref = lib.db.get_collection(db_conn, 'users')
@app.route("/hello")
@cross_origin()
def hello():
return "hello! Welcome to PIII!"
@app.route("/twitter/scan/<app_user>/<twitter_user>")
@cross_origin()
def scan_twitter(app_user, twitter_user):
user_account = twit.get_user_profile_data(twitter_user)
similar_accounts = twit.search_by_username(twitter_user)
cases = comparator.check_duplicates(
user_account.json(), similar_accounts.json())
for case in cases:
# Add cases to firestore
lib.db.add_cases(db_conn, app_user,
"https://twitter.com/" + case['username'])
return Response("{}", status=200, mimetype='application/json')
@app.route("/twitter/add_profile/<app_user>/<twitter_handle>")
@cross_origin()
def link_twitter_profile(app_user, twitter_handle):
user_account = twit.get_user_profile_data(twitter_handle)
user_account = user_account.json()
lib.db.add_twitter_account(db_conn, app_user, user_account['data'])
return user_account
port = int(os.environ.get('PORT', 8080))
if __name__ == '__main__':
app.run(threaded=True, host='0.0.0.0', port=port, debug=True)