refactor to auto import
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
ADD_LIST_ROUTE = "project/add"
|
||||
ADD_ITEM_ROUTE = "subject/add"
|
||||
TITLE = "استانها و شهرهای ایران"
|
||||
TYPE = 2
|
||||
|
||||
ADD_LIST_QUERY = {
|
||||
"title": TITLE,
|
||||
"type": 2,
|
||||
"item_state": 0,
|
||||
"ispublic" : 1,
|
||||
"tags": "province",
|
||||
}
|
||||
|
||||
# result= requests.post(BASE_URL + 'list/' + ADD_LIST_ROUTE, data=ADD_LIST_QUERY, headers = HEADERS)
|
||||
# print(result)
|
||||
# print(result.text)
|
||||
# projectid = json.loads(result.text)["data"]["id"]
|
||||
# exit()
|
||||
|
||||
projectid = 1000
|
||||
|
||||
# EXAMPLE_ADD_ITEM_QUERY = {
|
||||
# "title": "",
|
||||
# "projectid": projectid,
|
||||
# "listtype": 0,
|
||||
# "parent": 0,
|
||||
# }
|
||||
|
||||
|
||||
file_path = os.getcwd() + '/ostan.txt'
|
||||
lines = []
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
print(len(lines))
|
||||
|
||||
ostan_dic={}
|
||||
ostan_order = 0
|
||||
shahr_order = 0
|
||||
number = 0
|
||||
for line in lines:
|
||||
items = line.strip('\n').split('\t')
|
||||
# print(items)
|
||||
number +=1
|
||||
if len(items) != 2 :
|
||||
continue
|
||||
ostan=items[0]
|
||||
shahr=items[1]
|
||||
|
||||
if ostan not in ostan_dic:
|
||||
ostan_order= ostan_order+1
|
||||
payload = {
|
||||
"title": ostan,
|
||||
"projectid": projectid,
|
||||
"childorder": ostan_order,
|
||||
"listtype": 2,
|
||||
"parent": 0,
|
||||
}
|
||||
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=payload, headers=HEADERS)
|
||||
# print(result.text)
|
||||
id = json.loads(result.text)["data"][0]["id"]
|
||||
ostan_dic[ostan]=id
|
||||
|
||||
ostan_id=ostan_dic[ostan]
|
||||
shahr_order = shahr_order + 1
|
||||
payload = {
|
||||
"title": shahr,
|
||||
"projectid": projectid,
|
||||
"childorder": shahr_order,
|
||||
"listtype": 2,
|
||||
"parent": ostan_id,
|
||||
}
|
||||
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=payload, headers=HEADERS)
|
||||
id = json.loads(result.text)["data"][0]["id"]
|
||||
print('-'*10, id, ' ', shahr_order )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user