From f6170eed7b2bb47e7f5ca075d4b0f8db86f26946 Mon Sep 17 00:00:00 2001 From: pengtao Date: Tue, 15 Oct 2019 14:58:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A02001=20b=5FN=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_channel/mp2shushu.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/data_channel/mp2shushu.py b/data_channel/mp2shushu.py index 1bcd310..b35e0de 100644 --- a/data_channel/mp2shushu.py +++ b/data_channel/mp2shushu.py @@ -1,25 +1,45 @@ # -*- 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 r.json() + 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 = None - return result + 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() + self.write2csv(data) + self.upload2ss()