Skip to content
Snippets Groups Projects
Commit 8bcbcea5 authored by User Erdgeist's avatar User Erdgeist
Browse files

standardize config access

parent e8b020e2
No related branches found
No related tags found
No related merge requests found
......@@ -17,10 +17,10 @@ parser.add_argument("-c", "--config", help="Config file location", default="./co
args = parser.parse_args()
with open(args.config, mode="r", encoding="utf-8") as json_file:
config_data = json.load(json_file)
config = json.load(json_file)
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+config_data.get('frab-conference')+'-'+config_data.get('track')+'.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + config['frab-conference'] + '-' + config['track'] + '.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'Silence is golden. Gerd Eist.'
app.jinja_env.trim_blocks = True
......@@ -28,6 +28,8 @@ app.jinja_env.lstrip_blocks = True
db = SQLAlchemy(app)
config['frab-conf-url'] = config['frab-url'] + config['frab-conference']
class Event(db.Model):
"""An event as dumped from frab"""
frab_id = db.Column(db.Integer, primary_key=True)
......@@ -53,7 +55,7 @@ class EventRating(db.Model):
@app.route("/")
def root():
events = Event.query.all()
return render_template('index.html', events=events, json=json, config=config_data, cat=config_data.get('categories'))
return render_template('index.html', events=events, json=json, config=config)
@app.route('/api/ratings')
def get_ratings():
......@@ -111,23 +113,19 @@ def add_rating(eventid):
db.session.commit()
return jsonify({"result":"ok"})
def fetch_talks(config):
def fetch_talks():
sess = requests.Session()
new_session_page = sess.get(config.get('frab-url'))
new_session_page = sess.get(config['frab-url'])
tree = etree.HTML(new_session_page.text)
auth_token = tree.xpath("//meta[@name='csrf-token']")[0].get("content")
login_data = dict()
login_data['user[email]'] = config.get('frab-user')
login_data['user[password]'] = config.get('frab-password')
login_data['user[email]'] = config['frab-user']
login_data['user[password]'] = config['frab-password']
login_data['user[remember_me]'] = 1
login_data['authenticity_token'] = auth_token
frab = config.get('frab-url')
conf = config.get('frab-conference')
track = config.get('track-name')
sess.post(frab + 'users/sign_in?conference_acronym=' + conf + '&locale=en', login_data, verify=False)
response = sess.get(frab + 'en/'+conf+'/events?track_name=' + track + '&format=json', verify=False, stream=True)
sess.post(config['frab-url'] + 'users/sign_in?conference_acronym=' + config['frab-conference'] + '&locale=en', login_data, verify=False)
response = sess.get(config['frab-conf-url'] + '/events?track_name=' + config['track-name'] + '&format=json', verify=False, stream=True)
talks_json = json.loads(response.text)
......@@ -137,7 +135,7 @@ def fetch_talks(config):
imported = 0
for json_event in talks_json['events']:
# print (json_event)
rawhtml = sess.get(frab + 'en/' + conf + '/events/'+ str(json_event['id']), verify=False, stream=True)
rawhtml = sess.get(config['frab-conf-url'] + '/events/'+ str(json_event['id']), verify=False, stream=True)
tree = etree.HTML(rawhtml.text)
submission_notes = tree.xpath('//b[text()="Submission Notes(user and admin):"]')[0].tail.strip()
......@@ -157,16 +155,18 @@ def fetch_talks(config):
else:
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) )
imported += 1
for goner in Event.query.filter( Event.frab_id.notin_([ ev['id'] for ev in talks_json['events'] ])).all():
goner.state = 'gone'
db.session.commit()
print ('Conference: ' + conf + ', track: ' + track + ', imported ' + str(len(talks_json['events'])) + ' events, ' + str(imported) + ' new.')
print ('Conference: ' + config['track'] + ', track: ' + config['track'] + ', imported ' + str(len(talks_json['events'])) + ' events, ' + str(imported) + ' new.')
if __name__ == "__main__":
db.create_all()
if args.frab_import:
fetch_talks(config_data)
fetch_talks()
else:
app.run(host=config_data.get('host'), port=int(config_data.get('port')))
app.run(host=config.get('host', '127.0.0.1'), port=int(config.get('port', '8080')))
......@@ -2,7 +2,7 @@
<title>{{ config.get('frab-conference') }} {{ config.get('track') }} rating helper</title>
<head>
<script type="text/javascript">categories = {
{%- for category in cat -%}
{%- for category in config['categories'] -%}
'category{{ loop.index }}': '{{ category }}',
{%- endfor -%}
};
......@@ -45,7 +45,7 @@
<div class="event-rating hidden" id="event-rating-new">
<div class="event-rating-submitter"></div>
{%- for category in cat -%}
{%- for category in config['categories'] -%}
<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>
{%- endfor -%}
<div class="event-rating-comment"></div>
......@@ -54,7 +54,7 @@
<div id="event-own-rating">
<hr/>
<div class="label">comment</div><textarea rows="8" id="event-comment"></textarea>
{%- for category in cat -%}
{%- for category in config['categories'] -%}
<div class="category-slider" id="event-category{{loop.index}}-slider">
<div class="label">{{category}}:</div>
<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 @@
{% for ev in events -%}
<li class="event-list-item" event_state="{{ev.state}}" event_type="{{ev.event_type}}" id="event-{{ev.frab_id}}">
<div class="event-meter-bar">
{%- for m in range(1+cat|length) -%}
{%- for m in range(1+config['categories']|length) -%}
<meter class="top-meter meter-{{m}}" id="event-{{ev.frab_id}}-meter-{{m}}" value="0" min="0" max="100"></meter>
{%- endfor -%}
</div>
......@@ -80,7 +80,7 @@
{%- else -%}
<button onclick="do_remove_event('{{ev.frab_id}}')" title="remove this event" class="mini-button remove-button">del</button>
{%- endif -%}
<div class="event-title"><a href="{{ config.get('frab-url') }}en/{{ config.get('frab-conference')}}/events/{{ ev.frab_id }}/">{{ ev.title }}</a></div>
<div class="event-title"><a href="{{ config['frab-conf-url'] }}/events/{{ ev.frab_id }}/">{{ ev.title }}</a></div>
{%- if ev.subtitle -%}
<div class="event-subtitle"> {{ ev.subtitle }}</div>
{%- endif -%}
......@@ -90,7 +90,7 @@
{%- endif -%}
<div class="event-speaker"><em>speakers: </em>
{%- for speaker_id, speaker_name in json.loads(ev.speakers or '{}').items() -%}
<a href="{{ config.get('frab-url') }}en/{{ config.get('frab-conference') }}/people/{{speaker_id}}">{{speaker_name}}</a>&nbsp;
<a href="{{ config['frab-conf-url'] }}/people/{{speaker_id}}">{{speaker_name}}</a>&nbsp;
{%- endfor -%}
</div>
</div>
......@@ -106,7 +106,7 @@
<div class="event-rating" id="event-rating-{{ev.frab_id}}" submitter="{{rating.submitter}}">
<div class="event-rating-submitter">{{rating.submitter}}:</div>
{%- for category, value in json.loads(rating.rating_dict or '{}').items()|sort -%}
<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>
<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>
{%- endfor -%}
<div class="event-rating-comment">{{rating.comment}}</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment