47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
import requests
|
|
import logging
|
|
from ops.ss_virtual_create import SS_Virtual_command
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class Mp2shushu():
|
|
def __init__(self, channel, gameid):
|
|
self.mp_url = f"https://mp.kingsome.cn/api/open/promotion/co-list?channelid={channel}&gameid={gameid}"
|
|
self.filename = "/data/git/ops_interface/ops/csv/2001_b_n.csv"
|
|
|
|
def get_ad_list(self):
|
|
r = requests.get(self.mp_url)
|
|
if r.status_code == requests.codes.ok:
|
|
return self.split_data(r.json())
|
|
else:
|
|
return None
|
|
|
|
def split_data(self, data):
|
|
try:
|
|
result = data['result']
|
|
begin = "b_n,b_n_china"
|
|
text = ""
|
|
for line in result:
|
|
text += ','.join(line) + '\n'
|
|
result_new = f"{begin}\n{text}"
|
|
except Exception:
|
|
log.error(f"split {data} failed!", exc_info=True)
|
|
result_new = None
|
|
return result_new
|
|
|
|
def write2csv(self, data):
|
|
with open(self.filename, 'w') as f:
|
|
f.write(data)
|
|
|
|
def upload2ss(self):
|
|
ss = SS_Virtual_command()
|
|
ss.upload_2001_b_n()
|
|
|
|
|
|
def run(self):
|
|
data = self.get_ad_list()
|
|
log.info(f"get data was {data}")
|
|
self.write2csv(data)
|
|
self.upload2ss()
|