summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrater.py34
-rw-r--r--templates/index.html14
2 files changed, 24 insertions, 24 deletions
diff --git a/rater.py b/rater.py
index e1ed9c5..247c1d2 100755
--- a/rater.py
+++ b/rater.py
@@ -17,10 +17,10 @@ parser.add_argument("-c", "--config", help="Config file location", default="./co
17args = parser.parse_args() 17args = parser.parse_args()
18 18
19with open(args.config, mode="r", encoding="utf-8") as json_file: 19with 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
22app = Flask(__name__) 22app = Flask(__name__)
23app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+config_data.get('frab-conference')+'-'+config_data.get('track')+'.db' 23app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + config['frab-conference'] + '-' + config['track'] + '.db'
24app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False 24app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
25app.config['SECRET_KEY'] = 'Silence is golden. Gerd Eist.' 25app.config['SECRET_KEY'] = 'Silence is golden. Gerd Eist.'
26app.jinja_env.trim_blocks = True 26app.jinja_env.trim_blocks = True
@@ -28,6 +28,8 @@ app.jinja_env.lstrip_blocks = True
28 28
29db = SQLAlchemy(app) 29db = SQLAlchemy(app)
30 30
31config['frab-conf-url'] = config['frab-url'] + config['frab-conference']
32
31class Event(db.Model): 33class 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("/")
54def root(): 56def 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')
59def get_ratings(): 61def 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
114def fetch_talks(config): 116def 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
166if __name__ == "__main__": 166if __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
diff --git a/templates/index.html b/templates/index.html
index 13a8aec..c8ccf71 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -2,7 +2,7 @@
2<title>{{ config.get('frab-conference') }} {{ config.get('track') }} rating helper</title> 2<title>{{ config.get('frab-conference') }} {{ config.get('track') }} rating helper</title>
3<head> 3<head>
4<script type="text/javascript">categories = { 4<script type="text/javascript">categories = {
5 {%- for category in cat -%} 5 {%- for category in config['categories'] -%}
6 'category{{ loop.index }}': '{{ category }}', 6 'category{{ loop.index }}': '{{ category }}',
7 {%- endfor -%} 7 {%- endfor -%}
8 }; 8 };
@@ -45,7 +45,7 @@
45 45
46<div class="event-rating hidden" id="event-rating-new"> 46<div class="event-rating hidden" id="event-rating-new">
47 <div class="event-rating-submitter"></div> 47 <div class="event-rating-submitter"></div>
48 {%- for category in cat -%} 48 {%- for category in config['categories'] -%}
49 <div><meter category="category{{loop.index}}" value="0" min="0" max="100"></meter><span class="event-rating-category-output" category="category{{loop.index}}"> {{ category + " 0 %" }}</span></div> 49 <div><meter category="category{{loop.index}}" value="0" min="0" max="100"></meter><span class="event-rating-category-output" category="category{{loop.index}}"> {{ category + " 0 %" }}</span></div>
50 {%- endfor -%} 50 {%- endfor -%}
51 <div class="event-rating-comment"></div> 51 <div class="event-rating-comment"></div>
@@ -54,7 +54,7 @@
54<div id="event-own-rating"> 54<div id="event-own-rating">
55 <hr/> 55 <hr/>
56 <div class="label">comment</div><textarea rows="8" id="event-comment"></textarea> 56 <div class="label">comment</div><textarea rows="8" id="event-comment"></textarea>
57 {%- for category in cat -%} 57 {%- for category in config['categories'] -%}
58 <div class="category-slider" id="event-category{{loop.index}}-slider"> 58 <div class="category-slider" id="event-category{{loop.index}}-slider">
59 <div class="label">{{category}}:</div> 59 <div class="label">{{category}}:</div>
60 <div class="slider"><input category="category{{loop.index}}" type="range" min="0" max="100" step="5" oninput="changeVal('event-category{{loop.index}}-output', this.value)"></div> 60 <div class="slider"><input category="category{{loop.index}}" type="range" min="0" max="100" step="5" oninput="changeVal('event-category{{loop.index}}-output', this.value)"></div>
@@ -71,7 +71,7 @@
71{% for ev in events -%} 71{% for ev in events -%}
72 <li class="event-list-item" event_state="{{ev.state}}" event_type="{{ev.event_type}}" id="event-{{ev.frab_id}}"> 72 <li class="event-list-item" event_state="{{ev.state}}" event_type="{{ev.event_type}}" id="event-{{ev.frab_id}}">
73 <div class="event-meter-bar"> 73 <div class="event-meter-bar">
74 {%- for m in range(1+cat|length) -%} 74 {%- for m in range(1+config['categories']|length) -%}
75 <meter class="top-meter meter-{{m}}" id="event-{{ev.frab_id}}-meter-{{m}}" value="0" min="0" max="100"></meter> 75 <meter class="top-meter meter-{{m}}" id="event-{{ev.frab_id}}-meter-{{m}}" value="0" min="0" max="100"></meter>
76 {%- endfor -%} 76 {%- endfor -%}
77 </div> 77 </div>
@@ -80,7 +80,7 @@
80 {%- else -%} 80 {%- else -%}
81 <button onclick="do_remove_event('{{ev.frab_id}}')" title="remove this event" class="mini-button remove-button">del</button> 81 <button onclick="do_remove_event('{{ev.frab_id}}')" title="remove this event" class="mini-button remove-button">del</button>
82 {%- endif -%} 82 {%- endif -%}
83 <div class="event-title"><a href="{{ config.get('frab-url') }}en/{{ config.get('frab-conference')}}/events/{{ ev.frab_id }}/">{{ ev.title }}</a></div> 83 <div class="event-title"><a href="{{ config['frab-conf-url'] }}/events/{{ ev.frab_id }}/">{{ ev.title }}</a></div>
84 {%- if ev.subtitle -%} 84 {%- if ev.subtitle -%}
85 <div class="event-subtitle"> {{ ev.subtitle }}</div> 85 <div class="event-subtitle"> {{ ev.subtitle }}</div>
86 {%- endif -%} 86 {%- endif -%}
@@ -90,7 +90,7 @@
90 {%- endif -%} 90 {%- endif -%}
91 <div class="event-speaker"><em>speakers: </em> 91 <div class="event-speaker"><em>speakers: </em>
92 {%- for speaker_id, speaker_name in json.loads(ev.speakers or '{}').items() -%} 92 {%- for speaker_id, speaker_name in json.loads(ev.speakers or '{}').items() -%}
93 <a href="{{ config.get('frab-url') }}en/{{ config.get('frab-conference') }}/people/{{speaker_id}}">{{speaker_name}}</a>&nbsp; 93 <a href="{{ config['frab-conf-url'] }}/people/{{speaker_id}}">{{speaker_name}}</a>&nbsp;
94 {%- endfor -%} 94 {%- endfor -%}
95 </div> 95 </div>
96 </div> 96 </div>
@@ -106,7 +106,7 @@
106 <div class="event-rating" id="event-rating-{{ev.frab_id}}" submitter="{{rating.submitter}}"> 106 <div class="event-rating" id="event-rating-{{ev.frab_id}}" submitter="{{rating.submitter}}">
107 <div class="event-rating-submitter">{{rating.submitter}}:</div> 107 <div class="event-rating-submitter">{{rating.submitter}}:</div>
108 {%- for category, value in json.loads(rating.rating_dict or '{}').items()|sort -%} 108 {%- for category, value in json.loads(rating.rating_dict or '{}').items()|sort -%}
109 <div><meter category="{{category}}" value="{{value}}" min="0" max="100"></meter><span class="event-rating-category-output" category="{{category}}"> {{ cat[loop.index-1] + " " + value|string + " %" }}</span></div> 109 <div><meter category="{{category}}" value="{{value}}" min="0" max="100"></meter><span class="event-rating-category-output" category="{{category}}"> {{ config['categories'][loop.index-1] + " " + value|string + " %" }}</span></div>
110 {%- endfor -%} 110 {%- endfor -%}
111 <div class="event-rating-comment">{{rating.comment}}</div> 111 <div class="event-rating-comment">{{rating.comment}}</div>
112 </div> 112 </div>