|
import os |
|
from apscheduler.schedulers.background import BackgroundScheduler |
|
import requests |
|
import globs |
|
|
|
|
|
api_key_goo = os.getenv('api_key_g') |
|
spreadsheet_id = os.getenv('spreadsheet') |
|
sheet_name = "pH" |
|
|
|
|
|
scheduler = BackgroundScheduler() |
|
scheduler.start() |
|
|
|
def send_data_to_google_sheets(sheet_name): |
|
|
|
dey_graf = globs.dey |
|
wek_graf = globs.wek |
|
v_hid_graf = globs.v_hid |
|
v_min_graf = globs.v_min |
|
ph_graf = globs.ph |
|
|
|
|
|
new_values = [ |
|
[dey_graf, wek_graf, v_hid_graf, v_min_g_raf, ph_graf] |
|
] |
|
|
|
|
|
url = f'https://sheets.googleapis.com/v4/spreadsheets/{spreadsheet_id}/values/{sheet_name}:append?valueInputOption=RAW&key={api_key_goo}' |
|
|
|
|
|
headers = { |
|
'Content-Type': 'application/json' |
|
} |
|
|
|
|
|
response = requests.post(url, headers=headers, json={'values': new_values}) |
|
|
|
|
|
if response.status_code == 200: |
|
print('Данные успешно добавлены в таблицу.') |
|
else: |
|
print('Ошибка при добавлении данных в таблицу:', response.text) |
|
|
|
|
|
send_data_to_google_sheets(sheet_name) |
|
|
|
|
|
scheduler.add_job(send_data_to_google_sheets, 'interval', hours=1, args=[sheet_name]) |
|
|
|
|
|
try: |
|
while True: |
|
pass |
|
except (KeyboardInterrupt, SystemExit): |
|
scheduler.shutdown() |