-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.py
68 lines (44 loc) · 1.54 KB
/
utils.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import json
import random
from datetime import datetime
def read_json_file(path):
with open(path) as json_file:
data = json.load(json_file)
return data
def get_news(lang='sk', items=None):
news = []
counter = 0
for item in read_json_file(os.path.join('data', 'news.json')):
counter += 1
data = {
"date": datetime.strptime(item['date'], '%Y-%m-%d').date(),
"categories": item['categories']
}
if lang == "sk":
data["title"] = item['title_sk']
data["meta"] = item['meta_sk']
if lang == "en":
data["title"] = item['title_en']
data["meta"] = item['meta_en']
if 'url' in item.keys():
data['url'] = item['url']
news.append(data)
if items and counter >= items:
break
return news
def get_jobs():
print(read_json_file(os.path.join('data', 'jobs.json')))
return read_json_file(os.path.join('data', 'jobs.json'))
def encode_name(name):
return name.lower().replace('-', '--').replace(' ', '-')
def decode_name(encoded_name):
return encoded_name.lower().replace('-', ' ').replace(' ', '-')
def get_speakers():
return read_json_file(os.path.join('data', 'speakers.json'))
def get_talks():
return read_json_file(os.path.join('data', 'talks.json'))
def get_edu_speakers():
return read_json_file(os.path.join('data', 'edusummit_speakers.json'))
def get_edu_talks():
return read_json_file(os.path.join('data', 'edusummit_talks.json'))