Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
matched = []


def run(dataFile, matchesFile, directory=u'.'):
def run(dataFile, matchesFile, directory='.'):
'''
Given a data file and an output directory generate one html+css per
restaurant to said directory. Also generates an index page.
Expand All @@ -44,17 +44,17 @@ def run(dataFile, matchesFile, directory=u'.'):
index.append(makeRestaurant(i, restaurantData, directory))

# make html from index
f = codecs.open(u'%s/index.html' % directory, 'w', 'utf8')
f = codecs.open('%s/index.html' % directory, 'w', 'utf8')
f.write(makeIndex(index))
f.close()

# output matched and unmatched
global matched, unmatched
matched = list(set(matched))
unmatched = list(set(unmatched))
f = codecs.open(u'matchinfo.csv', 'w', 'utf8')
f.write(u'%s\n' % '|'.join(matched))
f.write(u'%s' % '|'.join(unmatched))
f = codecs.open('matchinfo.csv', 'w', 'utf8')
f.write('%s\n' % '|'.join(matched))
f.write('%s' % '|'.join(unmatched))
f.close()


Expand All @@ -72,14 +72,14 @@ def makeRestaurant(no, restaurantData, directory):
txt = intro(restaurantData['name'], no)

# add title
txt += u'''
txt += '''
%s<p class="restaurant-name"><mark>%s</mark></p>
%s<ul class="menu flow-text">''' % (4*block, restaurantData['name'], 4*block)
# add dishes
txt += ''.join(dishes)

# footer
txt += u'''
txt += '''
%s</ul>
%s</div>
%s</div>
Expand All @@ -88,22 +88,22 @@ def makeRestaurant(no, restaurantData, directory):
%s<br />''' % (4*block, 3*block, 2*block, 2*block, 3*block, 3*block)

# add imageref
txt += u'''
txt += '''
%sImage: <a href="https://commons.wikimedia.org/wiki/File:%s">%s</a> by %s, license: %s''' % (3*block, restaurantData['bg_img'].replace(' ', '_'), restaurantData['bg_img'], restaurantData['bg_credit'], restaurantData['bg_license'])

# add outro
txt += outro()

# output
f = codecs.open(u'%s/%r.html' % (directory, no), 'w', 'utf8')
f = codecs.open('%s/%r.html' % (directory, no), 'w', 'utf8')
f.write(txt)
f.close()

# make css
css = makeCss(restaurantData['colour'],
restaurantData['active_colour'],
restaurantData['bg_img'])
f = codecs.open(u'%s/%r.css' % (directory, no), 'w', 'utf8')
f = codecs.open('%s/%r.css' % (directory, no), 'w', 'utf8')
f.write(css)
f.close()

Expand All @@ -121,18 +121,18 @@ def makeDish(dishData):
ingredients.append(makeIngredient(ingredientData, indent+1))

# add title (and possibly coment)
txt = u'\n%s<li>' % ((indent-1)*block)
txt += u'\n%s<p class="dish">' % (indent*block)
txt = '\n%s<li>' % ((indent-1)*block)
txt += '\n%s<p class="dish">' % (indent*block)
txt += addQlabel(dishData['name'], indent+1)
if 'cmt' in dishData.keys():
if 'cmt' in list(dishData.keys()):
txt += addComment(dishData['cmt'], indent+2)

# add price
txt += u'\n%s<span class="price">%s</span>' % ((indent+1)*block, dishData['price'])
txt += u'\n%s</p>' % (indent*block)
txt += '\n%s<span class="price">%s</span>' % ((indent+1)*block, dishData['price'])
txt += '\n%s</p>' % (indent*block)

# ingredients with wrapper
txt += u'''
txt += '''
%s<p class="ingredient">%s
%s</p>''' % ((indent*block), ', '.join(ingredients), (indent*block))
# close
Expand All @@ -146,7 +146,7 @@ def makeIngredient(ingredientData, indent):
Given an ingredient object return a formated string
'''
txt = addQlabel(ingredientData['name'], indent)
if 'cmt' in ingredientData.keys():
if 'cmt' in list(ingredientData.keys()):
txt += addComment(ingredientData['cmt'], indent+1)
return txt

Expand All @@ -169,19 +169,19 @@ def addQlabel(entity, indent):
'''
global matched, unmatched
i = '' + indent * block
if entity in qMatches.keys():
if entity in list(qMatches.keys()):
matched.append(qMatches[entity])
return u'''
return '''
%s<a href="#" title="%s" data-toggle="popover" data-trigger="manual" data-placement="auto" data-content="Data not loaded yet :/" data-html="true">
%s<span class="qlabel" its-ta-ident-ref="http://www.wikidata.org/entity/%s">%s</span></a>''' % (i, entity, (indent+1)*block, qMatches[entity], entity)
else:
unmatched.append(entity)
return u'''
return '''
%s<span>%s</span>''' % (i, entity)


def intro(name, no):
return u'''<!DOCTYPE html>
return '''<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -224,15 +224,15 @@ def intro(name, no):


def outro():
return u'''
return '''
</div>
</body>
</html>'''


def makeCss(colour, active_colour, img):
img_url = u'https://commons.wikimedia.org/wiki/Special:Redirect/file?wptype=file&wpvalue=%s' % img.replace(' ', '+')
return u'''body{
img_url = 'https://commons.wikimedia.org/wiki/Special:Redirect/file?wptype=file&wpvalue=%s' % img.replace(' ', '+')
return '''body{
background-image: url("%s");
}

Expand All @@ -255,7 +255,7 @@ def makeCss(colour, active_colour, img):


def makeIndex(index):
txt = u'''<!DOCTYPE html>
txt = '''<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
Expand All @@ -281,12 +281,12 @@ def makeIndex(index):
<ul class="menu flow-text">'''

for i in range(0, len(index)):
txt += u'''
txt += '''
<li>
<p class="dish"><a href="%r.html">%r. %s</a></p>
</li>''' % (i+1, i+1, index[i])

txt += u'''
txt += '''
</ul>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions generator/tsv2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def run(dataFile, matchesFile):
iData['cmt'] = '%s' % p[3]
data[rId]['dishes'][dId]['ingredients'].append(iData.copy())
else:
print 'shit!'
print('shit!')

f = codecs.open(u'%s.json' % dataFile[:-len('.tsv')], 'w', 'utf8')
f = codecs.open('%s.json' % dataFile[:-len('.tsv')], 'w', 'utf8')
f.write(json.dumps(data, indent=4, ensure_ascii=False))
f.close()

Expand All @@ -85,11 +85,11 @@ def run(dataFile, matchesFile):
if len(l) == 0:
continue
p = l.split('\t')
if p[0] in matches.keys():
print 'duplicate word: %s' % p[0]
if p[0] in list(matches.keys()):
print('duplicate word: %s' % p[0])
else:
matches[p[0]] = p[1]

f = codecs.open(u'%s.json' % matchesFile[:-len('.tsv')], 'w', 'utf8')
f = codecs.open('%s.json' % matchesFile[:-len('.tsv')], 'w', 'utf8')
f.write(json.dumps(matches, indent=4, ensure_ascii=False))
f.close()