-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDL_code.py
More file actions
69 lines (56 loc) · 1.67 KB
/
DL_code.py
File metadata and controls
69 lines (56 loc) · 1.67 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
# -*- coding: utf-8 -*-
# あるユーザがAOJに提出した全コード(?)を保存する
from collections import defaultdict
import xml.etree.ElementTree as ET
import urllib.request
ME="Yazaten"
judgeURL = "http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid="
def getUser(id):
response = urllib.request.urlopen('http://judge.u-aizu.ac.jp/onlinejudge/webservice/user?id='+id)
return response
def getSolvedList(id):
list = []
html=getUser(id)
#
tree=ET.parse(html)
root=tree.getroot()
#
a = []
b = []
for problemid in root.findall(".//problem/id"):
a.append( problemid.text )
for judgeid in root.findall(".//problem/judge_id"):
b.append( judgeid.text )
#
for i in range(len(a)):
list.append( (a[i],b[i]) )
return list
def format( page ):
page = page.replace( b'<' , b'<' )
page = page.replace( b'>' , b'>' )
page = page.replace( b'"', b'\"')
page = page.replace( b'&', b'&')
page = page.replace( b' ', b' ')
page = page.replace( b' <pre class=\"brush: cpp\" name=\"code\" id=\"code\">', b'' )
page = page[:-1]
return page
problemList = getSolvedList(ME)
for i,problem in enumerate(problemList):
problemid = problem[0]
judgeid = problem[1]
html = urllib.request.urlopen( judgeURL+str(judgeid) )
list = []
flag = False
for page in html:
if page.count( b'#include' ):
flag = True
if flag == True:
if page.count( b'</pre>\n' ):
break
else :
page = format( page )
list.append(page)
f = open(str(problemid)+'.cpp', 'w') # 書き込みモードで開く
for line in list:
f.write( line.decode('utf-8')+'\n' ) # 引数の文字列をファイルに書き込む
f.close() # ファイルを閉じる