优化数据保存功能,添加时间戳并移除定时任务;新增获取general信息的功能
This commit is contained in:
19
general.py
19
general.py
@@ -1,7 +1,5 @@
|
|||||||
import csv
|
import csv
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
|
||||||
import schedule
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
PHASE_URL = "https://backend.dexrp.io/general/phase"
|
PHASE_URL = "https://backend.dexrp.io/general/phase"
|
||||||
@@ -23,8 +21,10 @@ def save_to_csv(filename, data):
|
|||||||
with open(filename, "a", newline="") as f:
|
with open(filename, "a", newline="") as f:
|
||||||
writer = csv.writer(f)
|
writer = csv.writer(f)
|
||||||
if f.tell() == 0: # Write header if file is empty
|
if f.tell() == 0: # Write header if file is empty
|
||||||
writer.writerow(data.keys())
|
writer.writerow(["datetime"] + list(data.keys()))
|
||||||
writer.writerow(data.values())
|
writer.writerow(
|
||||||
|
[datetime.now().strftime("%Y-%m-%d %H:%M:%S")] + list(data.values())
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error saving to {filename}: {e}")
|
print(f"Error saving to {filename}: {e}")
|
||||||
|
|
||||||
@@ -52,14 +52,5 @@ def job():
|
|||||||
save_to_csv("general.csv", filtered_general)
|
save_to_csv("general.csv", filtered_general)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
schedule.every(10).minutes.do(job)
|
|
||||||
job() # Run immediately first time
|
|
||||||
|
|
||||||
while True:
|
|
||||||
schedule.run_pending()
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
job()
|
||||||
|
8
main.py
8
main.py
@@ -162,6 +162,13 @@ def git_commit_and_push():
|
|||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
LOGGER.error("Git操作失败: %s", e)
|
LOGGER.error("Git操作失败: %s", e)
|
||||||
|
|
||||||
|
def general_info():
|
||||||
|
"""获取general信息"""
|
||||||
|
LOGGER.info("获取general信息")
|
||||||
|
try:
|
||||||
|
subprocess.run(["python", "general.py"], check=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
LOGGER.error("获取general信息失败: %s", e)
|
||||||
|
|
||||||
def load_processed_hashes():
|
def load_processed_hashes():
|
||||||
"""Load processed transaction hashes from file."""
|
"""Load processed transaction hashes from file."""
|
||||||
@@ -219,6 +226,7 @@ def main():
|
|||||||
|
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
if current_time - last_git_time >= GIT_INTERVAL:
|
if current_time - last_git_time >= GIT_INTERVAL:
|
||||||
|
general_info()
|
||||||
git_commit_and_push()
|
git_commit_and_push()
|
||||||
last_git_time = current_time
|
last_git_time = current_time
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user