Commit 537a9eb7 authored by christoffer.stoll's avatar christoffer.stoll
Browse files

first commit

parents
.DS_Store
*.xml
*.csv
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
.idea/misc.xml
.idea/modules.xml
profiles_settings.xml
Project_Default.xml
.idea/raven.iml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# Raven Import
Imports csv's into Raven
All csv files must be formatted according to Raven specification.
## NOTE
Not tested. Under development
## Requirements
This script requires **Raven** to be installed.
## Dependencies
* requests (pip install requests)
* python 3
## Arguments
**--url** Url to Raven
**--usr** Username for Raven
**--psw** Password for Raven
**--ra** Name of responsible authorities file
**--net** Name of networks file
**--sta** Name of stations file
**--spo** Name of sampling points file
**--spp** Name of processes file
**--sam** Name of samples file
**--oc** Name of observing capabilities file
**--obs** Name of observations file
## Usage
```
python raven.py --url http://localhost:5000 --usr usr --psw psw --ra ra.csv
```
import sys
import argparse
import requests
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--ra', help='Name of responsible authorities file ', default='')
parser.add_argument(
'--net', help='Name of networks file ', default='')
parser.add_argument(
'--sta', help='Name of stations file ', default='')
parser.add_argument(
'--spo', help='Name of sampling points file ', default='')
parser.add_argument(
'--spp', help='Name of processes file ', default='')
parser.add_argument(
'--sam', help='Name of samples file ', default='')
parser.add_argument(
'--oc', help='Name of observing capabilities file ', default='')
parser.add_argument(
'--obs', help='Name of observations file ', default='')
parser.add_argument(
'--url', help='Url to Raven', default='http://localhost:5000')
parser.add_argument(
'--usr', help='Username for Raven ', default='admin')
parser.add_argument(
'--psw', help='Password for Raven ', default='admin')
return parser.parse_args()
def import_to_raven(endpoint, path_to_csv):
FILES = {'csv': open(path_to_csv, 'rb')}
import_response = requests.post(
endpoint, files=FILES, auth=(args.usr, args.psw))
if import_response.status_code != 201:
print("Status code: " + str(import_response.status_code))
print("Error message: " + str(import_response.text))
sys.exit("Import failed. Exit!")
RA_ENDPOINT = "/imports/responsible_authorities"
NET_ENDPOINT = "/imports/networks"
STA_ENDPOINT = "/imports/stations"
SPO_ENDPOINT = "/imports/sampling_points"
SPP_ENDPOINT = "/imports/processes"
SAM_ENDPOINT = "/imports/samples"
OC_ENDPOINT = "/imports/observing_capabilities"
OBS_ENDPOINT = "/imports/observations"
try:
args = get_args()
if not args.ra:
print("Importing responsible authorities to Raven")
import_to_raven(args.url + RA_ENDPOINT, args.ra)
if not args.net:
print("Importing networks to Raven")
import_to_raven(args.url + NET_ENDPOINT, args.net)
if not args.sta:
print("Importing stations to Raven")
import_to_raven(args.url + STA_ENDPOINT, args.sta)
if not args.spo:
print("Importing sampling points to Raven")
import_to_raven(args.url + SPO_ENDPOINT, args.spo)
if not args.spp:
print("Importing processes to Raven")
import_to_raven(args.url + SPP_ENDPOINT, args.spp)
if not args.sam:
print("Importing samples to Raven")
import_to_raven(args.url + SAM_ENDPOINT, args.sam)
if not args.oc:
print("Importing observing capabilities to Raven")
import_to_raven(args.url + OC_ENDPOINT, args.oc)
if not args.obs:
print("Importing observations to Raven")
import_to_raven(args.url + OBS_ENDPOINT, args.obs)
print("Done")
except Exception as e:
sys.exit("Error: " + str(e))
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