forked from data-for-change/anyway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_import.py
30 lines (28 loc) · 1023 Bytes
/
simple_import.py
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
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import datetime
from constants import CONST
db_connection_string = os.environ.get('CLEARDB_DATABASE_URL')
print "using connection string: %s"%db_connection_string
engine = create_engine(db_connection_string, convert_unicode=True, echo=True)
autocommit = False # Autocommit does not seem to work
db_session = sessionmaker(autocommit=autocommit, autoflush=True, bind=engine)
Base = declarative_base()
session = db_session()
from models import Marker
marker = Marker(
user = None,
title = "Accident",
description = "sample accident",
address = "sample address",
latitude = "00.33",
longitude = "00.22",
type = CONST.MARKER_TYPE_ACCIDENT,
subtype = "",
created = datetime.datetime.now(),
)
session.add(marker)
if not autocommit:
session.commit()