-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_harvest.py
69 lines (59 loc) · 1.84 KB
/
example_harvest.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'''
Quick example of a harvest
'''
import logging
import dateutil.relativedelta
import dateutil.tz
import datetime
import igsn_lib.models
import igsn_lib.util
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pprint import pprint
def getEngine():
pguser = "igsn_cache"
pgpass = igsn_lib.util.getCredentials(pguser)
pgdatabase = "igsn_01"
engine = create_engine(f"postgresql+psycopg2://{pguser}:{pgpass}@localhost:5432/{pgdatabase}")
igsn_lib.models.createAll(engine)
return engine
def getSession(engine):
Session = sessionmaker(bind=engine)
session = Session()
return session
def testJoins():
logging.basicConfig(level=logging.DEBUG)
engine = getEngine()
session = getSession(engine)
url = "http://doidb.wdc-terra.org/igsnoaip/oai"
service = session.query(igsn_lib.models.Service)\
.filter(igsn_lib.models.Service.url==url)\
.first()
if service is None:
service = igsn_lib.models.addService(session, url)
print(service)
job = service.topupHarvestJob(session)
job.execute(session)
#print(f"{rec.id} {rec.oai_datestamp}")
session.close()
def main():
logging.basicConfig(level=logging.DEBUG)
#engine = create_engine('sqlite:///igsn_store.db')
engine = getEngine()
session = getSession(engine)
service = igsn_lib.models.addService(session, url="http://doidb.wdc-terra.org/igsnoaip/oai")
pprint(service)
pprint(service.jobs)
tuntil = datetime.datetime.now(dateutil.tz.UTC) + dateutil.relativedelta.relativedelta(days=-1)
tfrom = tuntil + dateutil.relativedelta.relativedelta(days=-365)
job = service.createJob(
session,
setspec='IEDA',
tfrom=tfrom,
tuntil=tuntil
)
job.execute(session)
session.close()
if __name__ == "__main__":
#testJoins()
main()