Add: onetime runnig files
This commit is contained in:
parent
746cc0ce2b
commit
341ba5ce93
66
cope2n-api/scripts/re_feedback.py
Normal file
66
cope2n-api/scripts/re_feedback.py
Normal file
@ -0,0 +1,66 @@
|
||||
import os
|
||||
import time
|
||||
import requests
|
||||
from datetime import datetime
|
||||
# from tqdm import tqdm
|
||||
|
||||
ROOT = "/root/TannedCung/sbt-idp/feedback"
|
||||
|
||||
interval = 3
|
||||
# Get the proxy URL from the environment variable
|
||||
proxy_url = os.getenv('PROXY', "localhost")
|
||||
|
||||
# Define the login API URL
|
||||
login_url = f'{proxy_url}/api/ctel/login/'
|
||||
login_token = None
|
||||
|
||||
# Define the login credentials
|
||||
login_credentials = {
|
||||
'username': 'sbt',
|
||||
# 'password': '7Eg4AbWIXDnufgn'
|
||||
'password': 'abc'
|
||||
}
|
||||
|
||||
# Define the command to call the update API
|
||||
update_url = f'{proxy_url}/api/ctel/images/feedback_file/'
|
||||
|
||||
def login():
|
||||
login_token = None
|
||||
login_response = requests.post(login_url, data=login_credentials)
|
||||
# login_response.raise_for_status()
|
||||
if login_response.status_code == 200:
|
||||
login_token = login_response.json()['token']
|
||||
print("[INFO] relogged in at {}".format(datetime.now()))
|
||||
return login_token
|
||||
|
||||
def feedback(login_token, file_path):
|
||||
headers = {'Authorization': login_token}
|
||||
files = {
|
||||
'files': (file_path.split("/")[-1], open(file_path, 'rb'), 'text/csv')
|
||||
}
|
||||
response = requests.post(update_url, headers=headers, files=files)
|
||||
|
||||
if response.status_code == 200:
|
||||
print('[INFO]: File uploaded successfully.')
|
||||
else:
|
||||
print('[ERROR]: File upload failed.')
|
||||
|
||||
def search_csv_files(directory):
|
||||
csv_files = []
|
||||
for root, dirs, files in os.walk(directory):
|
||||
for file in files:
|
||||
if file.endswith(".csv"):
|
||||
csv_files.append(os.path.join(root, file))
|
||||
|
||||
csv_files.sort(key=lambda path: int(os.path.basename(os.path.dirname(path))))
|
||||
return csv_files
|
||||
|
||||
def main():
|
||||
login_token = login()
|
||||
list_files = search_csv_files(ROOT)
|
||||
for _file in list_files:
|
||||
feedback(login_token, _file)
|
||||
time.sleep(interval)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -5,7 +5,7 @@ from datetime import datetime
|
||||
|
||||
# Get the proxy URL from the environment variable
|
||||
interval = 60*60*1 # 1 minute
|
||||
update_cost = 60*3
|
||||
update_cost = 60*2
|
||||
proxy_url = os.getenv('PROXY', "localhost")
|
||||
|
||||
# Define the login API URL
|
||||
@ -15,7 +15,8 @@ login_token = None
|
||||
# Define the login credentials
|
||||
login_credentials = {
|
||||
'username': 'sbt',
|
||||
'password': '7Eg4AbWIXDnufgn'
|
||||
# 'password': '7Eg4AbWIXDnufgn'
|
||||
'password': 'abc'
|
||||
}
|
||||
|
||||
# Define the command to call the update API
|
||||
|
Loading…
Reference in New Issue
Block a user