-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeim.py
More file actions
81 lines (73 loc) · 2.62 KB
/
deim.py
File metadata and controls
81 lines (73 loc) · 2.62 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
#coding=utf-8
import json,urllib2,os,re,string
# セッション情報をURLから取得する
# header: jsonデータにするために不必要なphrase
def loadProgramInfo(url,header):
try:
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
except:
raise
return loadProgramInfoFromJsonData(data,header)
# セッション情報をJSONファイルから取得
def loadProgramInfoFromJsonData(data,header):
lines = data.split(os.linesep)
page = ""
for line in lines:
line = line.replace(' ',' ')
line = re.sub(r'<u.*</u>','',line)
page = page + line
jsonstr = page.replace(header,'')
jsonstr = re.sub(r',(¥s|¥t| )*}','}',jsonstr)
jsonstr = re.sub(r',(¥s|¥t| )*]',']',jsonstr)
try:
program = json.loads(jsonstr, "utf-8")
except ValueError, e:
raise
return program
# 論文情報を取る
def getPaperInfo(url):
req = urllib2.Request(url)
response = urllib2.urlopen(req)
papers = getPaperInfoFromJsonData(response.read())
return papers
def getPaperInfoFromJsonData(data):
data = data.replace("callback(","")[:-1].replace(" "," ")
data = data.decode('utf-8')
# ゴミを取る
for i in range(0,32):
data = data.replace(unichr(i),'')
papers = json.loads(data)
return papers
# タイムスロットの情報を取得する
def getSlotInfo(program):
dayno = 0
curday = ""
slots = {}
for line in program["timetable"]:
try:
slot = {}
slotinfo = re.match(u'セッション(.*):(.*)月(.*)日[(\(](.*)[)\)](.*)〜(.*)',line)
month = zen2han(slotinfo.group(2))
day = zen2han(slotinfo.group(3))
start = zen2han(slotinfo.group(5))
end = zen2han(slotinfo.group(6))
slot["session_no"] = slotinfo.group(1)
if curday == "" or curday != month+"/"+day:
curday = month+"/"+day
dayno = dayno + 1
slot["date"] = curday
slot["day"] = dayno
slot["start"] = string.replace(start,u' ', u'')
slot["end"] = string.replace(end,u' ',u'')
slots[slotinfo.group(1)]=slot
except:
print "Description format may be changed. Check it."
raise
return slots
def zen2han(strnumber):
transmap = {u'1':"1",u'2':"2",u'3':"3",u'4':"4",u'5':"5",u'6':"6",u'7':"7",u'8':"8",u'9':"9",u'0':"0",u':':":"}
for zen in transmap.keys():
strnumber = strnumber.replace(zen, transmap[zen])
return strnumber