-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsql_al.py
More file actions
38 lines (30 loc) · 1.36 KB
/
sql_al.py
File metadata and controls
38 lines (30 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from model import db, WellMonthRates
import csv
from datetime import datetime, timedelta
app = Flask(__name__)
app.config.from_pyfile('config.py')
db = SQLAlchemy(app)
db.init_app(app)
wells_month = []
with open('..\merfond.csv', 'r', encoding = 'utf-8') as f:
mer = csv.DictReader(f, delimiter = ';')
for line in mer:
wells_month.append({ #добавление словаря в список словарей
'date' : line['\ufeffDT_1'],
'well_id' : line['SK_1'],
'name' : line['S1_1'],
'oil' : line['N1_1'],
'gas' : line['G1_1'],
'water' : line['V1_1'],
'injection' : line['Z1_1'],
'work_time' : line['TEKSR_1']
})
def save_measurement(well_id, name, date, oil, gas, water, injection, work_time):
# well_month_exists = WellMonthRates.query.filter(WellMonthRates.well_id == wells_month.well_id and WellMonthRates.name = wells_month.date).count()
#print(well_month_exists)
# if not well_month_exists:
well_date = WellMonthRates(name=wells_month.name, well_id=wells_month.well_id, date=wells_month.date)
db.session.add(well_date)
db.session.commit()