-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathURL.py
More file actions
119 lines (95 loc) · 3.26 KB
/
URL.py
File metadata and controls
119 lines (95 loc) · 3.26 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
from urllib.parse import urlencode, quote_plus
Key = "nzhfKajoHJmAX1gKiu5WyxWx2fbAfCxBWwOThdrb323YQrUlrW%2B1CmlnI3zWzZvdWwSHpP6665%2F8JdWBK1Pe4g%3D%3D"
#abstract link class
class Link:
def __init__(self):
pass
def search(self):
pass
def pageNo(int):
pass
#keywordlink
class KeywordLink(Link):
def __init__(self):
self.url = "http://apis.data.go.kr/B551011/KorService1/searchKeyword1?"
self.queryParams = "serviceKey=" + Key + '&' + urlencode({
quote_plus('MobileApp'): 'AppTest',
quote_plus('MobileOS'): 'ETC',
quote_plus('numOfRows') : '12',
quote_plus('_type') : 'json',
quote_plus('listYN') : 'Y',
quote_plus('arrange') : 'A'
#가나다 순 정렬
})
self.pNo = urlencode({quote_plus('pageNo') : 1})
self.word = None
def pageNo(self,num):
self.pNo = urlencode({quote_plus('pageNo') : num})
self.searchURL = self.url + self.queryParams + '&' + self.pNo + '&' +self.word
def search(self,keyword):
self.word = urlencode({quote_plus('keyword') : keyword})
#classification linkmaker
class ClassLink(Link):
def __init__(self):
self.url = "http://apis.data.go.kr/B551011/KorService1/areaBasedList1?"
self.queryParams = "serviceKey=" + Key + '&' + urlencode({
quote_plus('MobileApp'): 'AppTest',
quote_plus('MobileOS'): 'ETC',
quote_plus('numOfRows') : '12',
quote_plus('_type') : 'json',
quote_plus('listYN') : 'Y',
quote_plus('arrange') : 'A'
#가나다 순 정렬
})
self.pNo = urlencode({quote_plus('pageNo') : 1})
self.word = None
self.searchURL = None
def pageNo(self,num):
self.pNo = urlencode({quote_plus('pageNo') : num})
self.searchURL = self.url + self.queryParams + '&' + self.pNo + '&' +self.word
def search(self, big, mid): #big, mid 분류코드 형식 ex) A01 A0101 A01010100
self.word = urlencode({
quote_plus('cat1') : big,
quote_plus('cat2') : mid,
})
self.searchURL = self.url + self.queryParams + '&' + self.pNo + '&' +self.word
#abstract factory
class Linkmaker():
def __init__():
pass
def Create():
pass
def pageChange():
pass
class KeywordLmaker(Linkmaker):
def __init__ (self, keyword):
self.keylink = KeywordLink()
self.keyword = keyword
def Create(self):
self.keylink.search(self.keyword)
return self.keylink.url + self.keylink.queryParams + '&' + self.keylink.pNo + '&' + self.keylink.word
def pageChange(self, number):
self.keylink.pageNo(number)
return self.keylink.url + self.keylink.queryParams + '&' + self.keylink.pNo + '&' + self.keylink.word
class ClassLmaker(Linkmaker):
def __init__(self, big, mid):
self.classlink = ClassLink()
self.big = big
self.mid = mid
def Create(self):
self.classlink.search(self.big, self.mid)
def pageChange(self, number):
self.classlink.pageNo(number)
return self.classlink.url + self.classlink.queryParams + '&' + self.classlink.pNo + '&' + self.classlink.word
'''
klink = KeywordLmaker("에버")
clink = ClassLmaker("A01","A0101")
url = klink.Create()
print(url)
url = klink.pageChange(2)
print(url)
url = clink.Create()
print(url)
url = klink.pageChange(3)
print(url)
'''