Skip to content

Commit

Permalink
add wepiao
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyloner committed Jan 10, 2017
1 parent 68ce56a commit 1006106
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ www.cpbz.gov.cn --- 企业标准信息公共服务平台 企业信息
bjguahao.gov.cn --- 北京市预约挂号统一平台 预约信息

sysjk.ivdc.org.cn --- 国家兽药基础信息查询系统

wepiao.com --- 微票票房数据
72 changes: 72 additions & 0 deletions wepiao.com/piaofang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import requests
import json
import datetime
import openpyxl
import re

ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')

headers = {
'Host':'piaofang.wepiao.com',
'Referer':'https://piaofang.wepiao.com/?dateStart=2017-01-08&dateEnd=2017-01-08&scheduleState=day',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Content-Type':'application/json',
'Cookie':'bid=92f29664cc5349e5aec882b20c154843; _ga=GA1.2.787255948.1484027508; sid=60a4b8317a114c44b42ff551d10917fd; _ga=GA1.3.649727203.1484027202; _wp_uid_=2268946e-7889-4506-a5a2-1c7eb3944e2d'}

def day_get(d):
oneday = datetime.timedelta(days=1)
day = d - oneday
return day

def product_box_office(day):
data={
"movieFilter":{"showDateFrom":day,"showDateTo":day,"sortType":"desc"},
"paging":{"pageSize":"30"},
"lang":"cn"
}
html=requests.post('https://piaofang.wepiao.com/api/v1/index',data=json.dumps(data),headers=headers,timeout=30).text
json_data=json.loads(html)['movieBoxOffices']
movies=[]
keys=['movieId','movieName','showDate','movieNameEnglish','productBoxOffice','productTotalBoxOffice','productBoxOfficeRate','productScheduleRate','productTicketSeatRate','releaseDate']
for item in json_data:
line=[]
for key in keys:
try:
line.append(item[key])
except:
line.append('')
movies.append(line)
return movies

def write_to_excel():
excel=openpyxl.Workbook(write_only=True)
sheet=excel.create_sheet()
for line in open('./movies.txt','r'):
line=ILLEGAL_CHARACTERS_RE.sub('',line)
line=eval(line)
line.remove(line[3])
sheet.append(line)
excel.save('movies.xlsx')

def main():
day=datetime.datetime.now()
day=day_get(day)
while True:
day_str=str(day).split(' ')[0]
if day_str=='2014-01-01':
break
try:
movies=product_box_office(day_str)
except:
print(day_str,'failed')
continue
f=open('movies.txt','a')
for movie in movies:
f.write(str(movie)+'\n')
f.close()
print(day_str,'ok')
day=day_get(day)

write_to_excel()

0 comments on commit 1006106

Please sign in to comment.