示例#1
0
def handle_hot_brands(dy: Douyin):
    """热门品牌
    """
    categories, resp = dy.get_brand_category()
    saveRawResponse(resp, 'brand-category')
    time.sleep(1)
    brand_map = {}
    for category in categories:
        id = category['id']
        category = category['name']
        brands, resp = dy.get_hot_brand(int(id))
        time.sleep(1)
        saveBrandRawResponse(resp, category)
        brand_map[category] = brands
    md = generate_brand_md(brand_map)
    filename = '{}-brand.md'.format(util.current_date())
    file = os.path.join('archives', filename)
    util.write_text(file, md)
示例#2
0
def get_all_brands(dy: Douyin):
    """热门品牌
    """
    categories, resp = dy.get_brand_category()
    save_raw_response(resp, 'brand-category')
    time.sleep(1)

    brand_map = {}
    for category in categories:
        # 分类名称
        cname = category['name']
        cid = int(category['id'])
        brands, resp = dy.get_hot_brand(cid)
        save_brand_raw_response(resp, cname)
        brand_map[cname] = brands
        time.sleep(1)

    return brand_map
示例#3
0
def run():
    # 获取数据
    dy = Douyin()
    # 热搜
    searches, resp = dy.get_hot_search()
    save_raw_response(resp, 'hot-search')
    time.sleep(1)
    # 明星
    stars, resp = dy.get_hot_star()
    save_raw_response(resp, 'hot-star')
    time.sleep(1)
    # 直播
    lives, resp = dy.get_hot_live()
    save_raw_response(resp, 'hot-live')
    time.sleep(1)
    # 音乐
    musics, resp = dy.get_hot_music()
    save_raw_response(resp, 'hot-music')
    time.sleep(1)
    # 品牌
    brands = get_all_brands(dy)
    time.sleep(1)

    # 最新数据
    todayMd = generate_readme(searches, stars, lives, musics, brands)
    save_readme(todayMd)
    # 归档
    archiveMd = generate_archive_md(searches, stars, lives, musics, brands)
    save_archive_md(archiveMd)
示例#4
0
import random
import time

import MySQLdb
import emoji

from douyin import Douyin
d = Douyin()
cookie_list = [
        ['70344017904', 'd174f7386deb5394f50281cedc4398fc'],
        ['70378306997', '3702ffaf2e2c2401b28aadd936a62cf8'],
    ]

win_num = 0        # 成功数据统计
error_enum = 0     # 失败数据统计

conn = MySQLdb.connect(host='127.0.0.1', port=3306, user="******", password="******", db='douyin', charset="utf8")
cursor = conn.cursor()
dy5 = cursor.execute('select * from keywords')
uuid = cursor.fetchall()
j = 0
for i in range(0, len(uuid)):
    # url = random.sample(cookie_list, 1)[0]
    # print(url[0], url[1])
    keyword = uuid[i][1]
    print(i+1, keyword)
    print(j)
    if j > len(cookie_list) - 1:
        j = 0  #123
    print(cookie_list[j][0], cookie_list[j][1])
    res = d.keywords(cookie_list[j][0], cookie_list[j][1], keyword)