Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加看看新闻网epg #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crawl/spiders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from crawl.spiders.gxntv import get_epgs_gxntv,get_channels_gxntv
from utils.general import chuanliu_Authorization
from crawl.spiders.sdtv import get_epgs_sdtv,get_channels_sdtv
from crawl.spiders.kankan import get_epgs_kankan,get_channels_kankan
epg_funcs = {
'tvmao':get_epgs_tvmao2,
'tbc':get_epgs_tbc,
Expand All @@ -41,6 +42,7 @@
'mytvsuper':get_epgs_mytvsuper,
'gxntv':get_epgs_gxntv,
'sdtv':get_epgs_sdtv,
'kankan':get_epgs_kankan,
} #所有EPG的接口
epg_source = {
'tvmao':get_channels_tvmao,
Expand All @@ -62,6 +64,7 @@
'mytvsuper':get_channels_mytvsuper,
'gxntv':get_channels_gxntv,
'sdtv':get_channels_sdtv,
'kankan':get_channels_kankan,
}
func_args = {
'tvmao':0,
Expand All @@ -83,6 +86,7 @@
'mytvsuper':0,
'gxntv':0,
'sdtv':0,
'kankan':0,
}
def epg_func(channel,id,dt,func_arg=0,source = 0):
if source:
Expand Down Expand Up @@ -111,6 +115,7 @@ def epg_func(channel,id,dt,func_arg=0,source = 0):
'get_epgs_mytvsuper',
'get_epgs_gxntv',
'get_epgs_sdtv',
'get_epgs_kankan',
'epg_funcs',
'func_args',
'epg_func',
Expand Down
92 changes: 92 additions & 0 deletions crawl/spiders/kankan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding:utf-8 -*-
# 看看新闻网-官网来源,上海6个频道
import requests, datetime, os, re, time, json, hashlib
from utils.general import headers
from bs4 import BeautifulSoup as bs

def get_epgs_kankan(channel, channel_id, dt, func_arg):
epgs = []
msg = ''
success = 1
timestamp = int(time.time())
date = dt.strftime("%Y-%m-%d")
payload = {}
params = {
'Api-Version': 'v1',
'channel_id': channel_id,
'date': date,
'nonce': '1',
'platform': 'pc',
'timestamp': timestamp,
'version': 'v2.0.0',
}
s = '&'.join([f'{key}={params[key]}' for key in sorted(params.keys())])
s = f'{s}&28c8edde3d61a0411511d3b1866f0636'
hashed_s = hashlib.md5(s.encode()).hexdigest()
sign = hashlib.md5(hashed_s.encode()).hexdigest()
headers = {
'Api-version': 'v1',
'nonce': '1',
'platform': 'pc',
'version': 'v2.0.0',
'sign': sign,
'timestamp': str(timestamp),
}
try:
url = f"https://kapi.kankanews.com/content/pc/tv/programs?channel_id={channel_id}&date={date}"
res = requests.request("GET", url, headers=headers, data=payload, timeout=8)
res.encoding = 'utf-8'
re_json = json.loads(res.text)
contents = re_json['result']['programs']
for content in contents:
starttime = datetime.datetime.fromtimestamp(content['start_time'])
endtime = datetime.datetime.fromtimestamp(content['end_time'])
title = content['name']
epg = {'channel_id': channel_id,
'starttime': starttime,
'endtime': endtime,
'title': title,
'desc': '',
'program_date': dt,
}
epgs.append(epg)
except Exception as e:
success = 0
spidername = os.path.basename(__file__).split('.')[0]
msg = f'spider-{spidername}- {e}'
return {
'success': success,
'epgs': epgs,
'msg': msg,
'last_program_date': dt,
'ban': 0,
}

def get_channels_kankan(): # sourcery skip: avoid-builtin-shadow
ids = {'东方卫视': '1',
'新闻综合': '2',
'第一财经': '5',
'纪实人文': '6',
'都市频道': '4',
'哈哈炫动': '9'}
channels = []
url = 'https://live.kankanews.com/huikan/'
res = requests.get(url)
res.encoding = 'utf-8'
soup = bs(res.text,'html.parser')
div_channels = soup.select('div.channel.item.cur > li')
for div_channel in div_channels:
name = div_channel.p.text.strip()
id = ids[name]
channel = {
'name': name,
'id': [id],
'url': url,
'source': 'kankan',
'logo': '',
'desc': '',
'sort': '上海',
}
channels.append(channel)
print(f'共有:{len(channels)}个频道')
return channels
1 change: 1 addition & 0 deletions web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Channel(models.Model):
('mytvsuper','myTVSUPER'),
('gxntv','广西网络广播电视'),
('sdtv','山东齐鲁'),
('kankan','看看新闻网'),
]
need_get = [
(1,'是'),
Expand Down