from typing import NoReturn
from selenium import webdriver
import time
import networkx as nx
import dataset
import pickle
import codecs
import sys
import os
import time
import re
import pandas as pd
import datetime
import dataset
import jinja2
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
fname=os.path.abspath(__file__)
elmts=fname.split(os.path.sep)
path2=os.path.sep.join(elmts[0:-1])
keysdir=path2+os.path.sep+'static'+os.path.sep
templateLoader = jinja2.FileSystemLoader(searchpath=keysdir)
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "designer.tmpl"
template = templateEnv.get_template(TEMPLATE_FILE)
repeat={}
displaydata=[]
cursor=db.query('SELECT designer,searchome,c_100,hhh,dt FROM hhh.rank_summary order by dt desc,hhh asc;')
for c in cursor:
designer=c['designer']
if repeat.get(designer) is None:
repeat[designer]=1
hhh=c['hhh']
c_100=c['c_100']
searchome=c['searchome']
hhh_label=''
if c_100==-1:
c100_label=' '
else:
# sch_label='設計家('+str(c['searchome'])+')'
c100_label=''
if searchome==-1:
sch_label=' '
else:
# sch_label='設計家('+str(c['searchome'])+')'
sch_label=''
local_lst=[]
if hhh > 0:
local_lst.append(('hhh',hhh))
if searchome > 0:
local_lst.append(('searchome',searchome))
if c_100 > 0:
local_lst.append(('c_100',c_100))
sorted_by_second = sorted(local_lst, key=lambda tup: tup[1])
print(sorted_by_second)
# local_lst.sort()
# if hhh0:
# if c_100>0:
# if c_100 < searchome
# second=sch_label
# else:
first=None
second=None
slen=len(sorted_by_second)
results=[]
for l in sorted_by_second:
if l[0]=='hhh':
results.append(hhh_label)
if l[0]=='searchome':
results.append(sch_label)
if l[0]=='c_100':
results.append(c100_label)
if slen==1:
results.append(' ')
displaydata.append({'designer':designer,'first':results[0],'second':results[1],'dt':c['dt']})
#
#displaydata=[{'a':'aaa','b':'bbb','c':'ccc'},{'a':'aaa2','b':'bbb2','c':'ccc2'}]
outputText = template.render(displaydata=displaydata)
fw=codecs.open('c:/tmp/output.html','w','utf-8')
fw.write(outputText)
fw.close()
os.startfile('c:/tmp/output.html')
print(outputText)