-
Notifications
You must be signed in to change notification settings - Fork 85
/
dianping.py
52 lines (41 loc) · 1.45 KB
/
dianping.py
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
#coding:utf-8
import requests
from settings import *
from config import PROVINCE_FILE_PATH,\
CITY_DETAIL_FILE_PATH
from util.dianping import get_provinces,get_active_cities
from decorator.dianping import recover
class DianPing(object):
"""
大众点评
"""
_provinces = None
_active_cities = None
def __new__(cls, *args, **kwargs):
if not hasattr(cls, '_instance'):
cls._instance = super(DianPing, cls).__new__(cls)
return cls._instance
def __init__(self):
self.session = requests.session()
@property
def provinces(self):
return self._provinces if self._provinces else self.get_provinces()
@property
def active_cities(self):
return self._active_cities if self._active_cities else self.get_active_cities()
@recover('_provinces',API_PROVINCE,PROVINCE_FILE_PATH)
def get_provinces(self,reget=False):
"""
获取所有省、直辖市的信息
:param reget: 重新抓取
"""
self._provinces = get_provinces(self.session,API_PROVINCE)
return self._provinces
@recover('_active_cities', API_PLACES, CITY_DETAIL_FILE_PATH)
def get_active_cities(self,reget=False):
"""
获取国内所有可见的地区、城市、县乡镇等的信息
:param reget: 重新抓取
"""
self._active_cities = get_active_cities(self.session,API_PLACES,self.provinces)
return self._active_cities