diff options
Diffstat (limited to 'rater.py')
-rwxr-xr-x | rater.py | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -17,10 +17,10 @@ parser.add_argument("-c", "--config", help="Config file location", default="./co | |||
17 | args = parser.parse_args() | 17 | args = parser.parse_args() |
18 | 18 | ||
19 | with open(args.config, mode="r", encoding="utf-8") as json_file: | 19 | with open(args.config, mode="r", encoding="utf-8") as json_file: |
20 | config_data = json.load(json_file) | 20 | config = json.load(json_file) |
21 | 21 | ||
22 | app = Flask(__name__) | 22 | app = Flask(__name__) |
23 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+config_data.get('frab-conference')+'-'+config_data.get('track')+'.db' | 23 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + config['frab-conference'] + '-' + config['track'] + '.db' |
24 | app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | 24 | app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False |
25 | app.config['SECRET_KEY'] = 'Silence is golden. Gerd Eist.' | 25 | app.config['SECRET_KEY'] = 'Silence is golden. Gerd Eist.' |
26 | app.jinja_env.trim_blocks = True | 26 | app.jinja_env.trim_blocks = True |
@@ -28,6 +28,8 @@ app.jinja_env.lstrip_blocks = True | |||
28 | 28 | ||
29 | db = SQLAlchemy(app) | 29 | db = SQLAlchemy(app) |
30 | 30 | ||
31 | config['frab-conf-url'] = config['frab-url'] + config['frab-conference'] | ||
32 | |||
31 | class Event(db.Model): | 33 | class Event(db.Model): |
32 | """An event as dumped from frab""" | 34 | """An event as dumped from frab""" |
33 | frab_id = db.Column(db.Integer, primary_key=True) | 35 | frab_id = db.Column(db.Integer, primary_key=True) |
@@ -53,7 +55,7 @@ class EventRating(db.Model): | |||
53 | @app.route("/") | 55 | @app.route("/") |
54 | def root(): | 56 | def root(): |
55 | events = Event.query.all() | 57 | events = Event.query.all() |
56 | return render_template('index.html', events=events, json=json, config=config_data, cat=config_data.get('categories')) | 58 | return render_template('index.html', events=events, json=json, config=config) |
57 | 59 | ||
58 | @app.route('/api/ratings') | 60 | @app.route('/api/ratings') |
59 | def get_ratings(): | 61 | def get_ratings(): |
@@ -111,23 +113,19 @@ def add_rating(eventid): | |||
111 | db.session.commit() | 113 | db.session.commit() |
112 | return jsonify({"result":"ok"}) | 114 | return jsonify({"result":"ok"}) |
113 | 115 | ||
114 | def fetch_talks(config): | 116 | def fetch_talks(): |
115 | sess = requests.Session() | 117 | sess = requests.Session() |
116 | new_session_page = sess.get(config.get('frab-url')) | 118 | new_session_page = sess.get(config['frab-url']) |
117 | tree = etree.HTML(new_session_page.text) | 119 | tree = etree.HTML(new_session_page.text) |
118 | auth_token = tree.xpath("//meta[@name='csrf-token']")[0].get("content") | 120 | auth_token = tree.xpath("//meta[@name='csrf-token']")[0].get("content") |
119 | login_data = dict() | 121 | login_data = dict() |
120 | login_data['user[email]'] = config.get('frab-user') | 122 | login_data['user[email]'] = config['frab-user'] |
121 | login_data['user[password]'] = config.get('frab-password') | 123 | login_data['user[password]'] = config['frab-password'] |
122 | login_data['user[remember_me]'] = 1 | 124 | login_data['user[remember_me]'] = 1 |
123 | login_data['authenticity_token'] = auth_token | 125 | login_data['authenticity_token'] = auth_token |
124 | 126 | ||
125 | frab = config.get('frab-url') | 127 | sess.post(config['frab-url'] + 'users/sign_in?conference_acronym=' + config['frab-conference'] + '&locale=en', login_data, verify=False) |
126 | conf = config.get('frab-conference') | 128 | response = sess.get(config['frab-conf-url'] + '/events?track_name=' + config['track-name'] + '&format=json', verify=False, stream=True) |
127 | track = config.get('track-name') | ||
128 | |||
129 | sess.post(frab + 'users/sign_in?conference_acronym=' + conf + '&locale=en', login_data, verify=False) | ||
130 | response = sess.get(frab + 'en/'+conf+'/events?track_name=' + track + '&format=json', verify=False, stream=True) | ||
131 | 129 | ||
132 | talks_json = json.loads(response.text) | 130 | talks_json = json.loads(response.text) |
133 | 131 | ||
@@ -137,7 +135,7 @@ def fetch_talks(config): | |||
137 | imported = 0 | 135 | imported = 0 |
138 | for json_event in talks_json['events']: | 136 | for json_event in talks_json['events']: |
139 | # print (json_event) | 137 | # print (json_event) |
140 | rawhtml = sess.get(frab + 'en/' + conf + '/events/'+ str(json_event['id']), verify=False, stream=True) | 138 | rawhtml = sess.get(config['frab-conf-url'] + '/events/'+ str(json_event['id']), verify=False, stream=True) |
141 | tree = etree.HTML(rawhtml.text) | 139 | tree = etree.HTML(rawhtml.text) |
142 | submission_notes = tree.xpath('//b[text()="Submission Notes(user and admin):"]')[0].tail.strip() | 140 | submission_notes = tree.xpath('//b[text()="Submission Notes(user and admin):"]')[0].tail.strip() |
143 | 141 | ||
@@ -157,16 +155,18 @@ def fetch_talks(config): | |||
157 | else: | 155 | else: |
158 | db.session.add( Event( frab_id = json_event['id'], title = json_event['title'], subtitle = json_event['subtitle'], abstract = json_event['abstract'], description = json_event['description'], speakers = json.dumps(speakers), state = json_event.get('state', 'new'), event_type = json_event['type'], notes = submission_notes) ) | 156 | db.session.add( Event( frab_id = json_event['id'], title = json_event['title'], subtitle = json_event['subtitle'], abstract = json_event['abstract'], description = json_event['description'], speakers = json.dumps(speakers), state = json_event.get('state', 'new'), event_type = json_event['type'], notes = submission_notes) ) |
159 | imported += 1 | 157 | imported += 1 |
158 | |||
160 | for goner in Event.query.filter( Event.frab_id.notin_([ ev['id'] for ev in talks_json['events'] ])).all(): | 159 | for goner in Event.query.filter( Event.frab_id.notin_([ ev['id'] for ev in talks_json['events'] ])).all(): |
161 | goner.state = 'gone' | 160 | goner.state = 'gone' |
161 | |||
162 | db.session.commit() | 162 | db.session.commit() |
163 | print ('Conference: ' + conf + ', track: ' + track + ', imported ' + str(len(talks_json['events'])) + ' events, ' + str(imported) + ' new.') | 163 | print ('Conference: ' + config['track'] + ', track: ' + config['track'] + ', imported ' + str(len(talks_json['events'])) + ' events, ' + str(imported) + ' new.') |
164 | 164 | ||
165 | 165 | ||
166 | if __name__ == "__main__": | 166 | if __name__ == "__main__": |
167 | db.create_all() | 167 | db.create_all() |
168 | if args.frab_import: | 168 | if args.frab_import: |
169 | fetch_talks(config_data) | 169 | fetch_talks() |
170 | else: | 170 | else: |
171 | app.run(host=config_data.get('host'), port=int(config_data.get('port'))) | 171 | app.run(host=config.get('host', '127.0.0.1'), port=int(config.get('port', '8080'))) |
172 | 172 | ||