1 Star 0 Fork 2

陈汐/add_category_and_value

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
update_data.py 3.07 KB
一键复制 编辑 原始数据 按行查看 历史
李新 提交于 2018-08-07 14:23 . 批量修改indicator_data
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/8/7 11:23
# @Author : Orient
# @File : update_data.py
# @Software: PyCharm
import requests
import json
import xlrd
params = {"passWord": "123456", "userName": "lidongfang"}
class get_cookie(object):
"""docstring for get_cookie."""
def __init__(self):
super(get_cookie, self).__init__()
def cookie(self):
url = 'http://backend.aqlicai.cn/login/loginIn.form'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
# 请求login接口
response = requests.post(url=url, params=params, headers=headers)
# 获取response中的cookies
cookies = response.cookies.get_dict()
return cookies
class encaps_data(object):
"""docstring for encapsulate_data."""
def __init__(self, ):
super(encaps_data, self).__init__()
self.dict = {
'id':'',
'categoryId':'',
'indicatorCode':'',
'indicatorData':'',
'indicatorTime':'',
'status':''}
def get_column_index(self,table, columnName):
columnIndex = None
for i in range(table.ncols):
if (table.cell_value(0, i) == columnName):
columnIndex = i
break
return columnIndex
def encaps(self):
"""
Args:
self,file_id
Returns:
data_json
"""
file_id = int(input('file_id: '))
with xlrd.open_workbook(f'./update_data/update_{file_id}.xls') as tb:
ts = tb.sheet_by_index(0)
for key in self.dict.keys():
self.dict[key] = ts.cell_value(1, self.get_column_index(ts,key))
data = {
"categoryId": int(self.dict['categoryId']),
"id": int(self.dict['indicatorCode']),
"edbIndicatorDataVOS": [{
"id": int(self.dict['id']),
"indicatorTime": "2018-08-07",
"indicatorData": str(self.dict['indicatorData']),
"status": str(int(self.dict['status']))
}]}
return json.dumps(data)
class update(get_cookie,encaps_data):
"""docstring for update."""
def __init__(self, ):
super(update, self).__init__()
def update(self):
"""批量修改indicator_data
Args:
self
Returns:
update status
"""
url = 'http://backend.aqlicai.cn/edb/center/saveData.form'
Headers = {'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
'X-Requested-With': 'XMLHttpRequest'}
data_json = encaps_data.encaps(self)
cookie = get_cookie.cookie(self)
result = requests.post(url,data = data_json, headers = Headers, cookies = cookie)
print(result.text)
test = update()
test.update()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gxchenxi/add_category_and_value.git
git@gitee.com:gxchenxi/add_category_and_value.git
gxchenxi
add_category_and_value
add_category_and_value
master

搜索帮助