Commit 84aa17c6 authored by Christoffer Stoll's avatar Christoffer Stoll
Browse files

added a start position for hours to be calculated

parent 98077da0
......@@ -9,10 +9,11 @@ Retrieves data for Albania from external server and converts it to Raven friendl
**--output** Name of resulting csv file
**--usr** Username for the external server
**--psw** Password for the external server
**--hours** The number of hours from "now" to collect data
**--hours** The number of hours from "pos" to collect data
**--pos** What datetime position to use in months from now. Default is 0 (today)
## Usage
```
python al2obs.py --output observations.csv --usr username --psw password --hours 3
python al2obs.py --output observations.csv --usr username --psw password --hours 3 --pos 5
```
import requests
import json
from datetime import date, timedelta
from datetime import date, timedelta, datetime as dt
import os.path
import csv
import io
from contextlib import closing
import codecs
import re
import datetime
import argparse
import datetime
def get_args():
......@@ -16,7 +16,8 @@ def get_args():
parser.add_argument('--usr', help='Username for the external server', default='')
parser.add_argument('--psw', help='Password for the external server', default='')
parser.add_argument('--output', help='Name of output file', default='observations.csv')
parser.add_argument('--hours', help='Hours ', default=1, type=int)
parser.add_argument('--hours', help='Number of hours of data ', default=1, type=int)
parser.add_argument('--pos', help='What datetime position to use in months from now. Default is todays date', default=0, type=int)
return parser.parse_args()
......@@ -33,8 +34,8 @@ columns = ["sampling_point_id", "begin_position", "end_position", "value", "veri
print("Setting up variables")
dateTo = date.today()
dateFrom = dateTo - timedelta(args.hours)
dateTo = dt.now() - timedelta(args.pos*365/12)
dateFrom = dateTo - timedelta(hours=args.hours)
pms = {}
hds = {}
mappings = {}
......@@ -67,7 +68,6 @@ resp = requests.post(url, data=pms, headers=hds, auth=(usr, pwd))
# Convert data
print("Converting external data to Raven observation format")
pattern = '[^\[\]]* \([^\(]+\)'
reader = csv.DictReader(resp.text.strip().split('\n'), delimiter=';')
for row in reader:
if len(row["Datum"]) > 10:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment