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
# -*- coding: utf-8 -*-
'''
app安装量,定时任务,每天运行一次
'''
import json
import logging
import os
import sys
import time
import requests
from common.mysql_uitl import save_result, save_etl_log
from common.time_util import YMDHMS_FORMAT, now_str
logging.basicConfig(format="%(asctime)s %(name)s:%(levelname)s:%(message)s", datefmt="%Y-%m-%d %H:%M:%S", level=logging.INFO)
file_name = sys.argv[0]
task_file = os.path.split(__file__)[-1].split(".")[0]
def dwd_app_install(data_dt):
start_date = (datetime.datetime.strptime(data_dt, "%Y-%m-%d") - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
end_date = data_dt
android_url = f'https://data.openinstall.io/data/event/growth?apiKey' \
f'=3b2b8553beaf1bd0ad4443f7a43ecc705ddf20880e84d1c360df664f&platform=android&beginDate={start_date}' \
f'&endDate={end_date}&groupBy=day&excludeDuplication=1'
ios_url = f'https://data.openinstall.io/data/event/growth?apiKey' \
f'=3b2b8553beaf1bd0ad4443f7a43ecc705ddf20880e84d1c360df664f&platform=ios&beginDate={start_date}&endDate' \
f'={end_date}&groupBy=day&excludeDuplication=1'
android_dict = get_app_install(android_url, 'android')
ios_dict = get_app_install(ios_url, 'ios')
ret_dict = dict(android_dict, **ios_dict)
total_app_num = ret_dict['android_num'] + ret_dict['ios_num']
ret_dict['total_app_num'] = total_app_num
if ret_dict:
ret_list = list()
ret_list.append(ret_dict)
row = save_result('tamp_data_dwd', 'dwd_app_install', ret_list, file_name)
now_time = now_str(YMDHMS_FORMAT)
save_etl_log('tamp_data_dwd', 'dwd_app_install', data_dt, row, 'done', task_file, now_time)
def get_app_install(url, app_type):
function_name = sys._getframe().f_code.co_name
logging.info(f'{function_name} start')
response_ret = requests.get(url)
content = response_ret.content.decode()
content_dict = json.loads(content)
body = content_dict['body']
install_dict = {}
for i in body:
data_dt = i['date'][0: 10]
app_name = i['install']
if app_type == 'android':
install_dict = dict(data_dt=data_dt, android_num=app_name)
elif app_type == 'ios':
install_dict = dict(data_dt=data_dt, ios_num=app_name)
return install_dict
if __name__ == '__main__':
# dwd_app_install(data_dt)
import datetime
begin = datetime.date(2021, 9, 18)
end = datetime.date(2021, 9, 22)
data_dt = begin
delta = datetime.timedelta(days=1)
while data_dt <= end:
print(data_dt.strftime("%Y-%m-%d"))
dwd_app_install(str(data_dt))
data_dt += delta