Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Travelogues Extraction
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labs-team
Travelogues Extraction
Commits
edcf12dc
Commit
edcf12dc
authored
4 years ago
by
philip.roeggla
Browse files
Options
Downloads
Patches
Plain Diff
typo
parent
61323a0a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
travelogues_extraction/getrecords/session.py
+54
-11
54 additions, 11 deletions
travelogues_extraction/getrecords/session.py
with
54 additions
and
11 deletions
travelogues_extraction/getrecords/session.py
+
54
−
11
View file @
edcf12dc
import
asyncio
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
import
typing
import
typing
import
httpcore
from
lxml
import
etree
as
lxmletree
from
lxml
import
etree
as
lxmletree
import
httpx
import
httpx
...
@@ -16,6 +18,7 @@ class RecordRetriever:
...
@@ -16,6 +18,7 @@ class RecordRetriever:
log
:
list
log
:
list
all_ok
:
bool
all_ok
:
bool
sleep
:
float
record_xpath
=
lxmletree
.
XPath
(
record_xpath
=
lxmletree
.
XPath
(
r
'
/srw:searchRetrieveResponse/srw:records/srw:record[1]/srw:recordData/marc:record[1]
'
,
r
'
/srw:searchRetrieveResponse/srw:records/srw:record[1]/srw:recordData/marc:record[1]
'
,
...
@@ -27,6 +30,7 @@ class RecordRetriever:
...
@@ -27,6 +30,7 @@ class RecordRetriever:
self
.
log
=
[]
self
.
log
=
[]
self
.
all_ok
=
True
# so far
self
.
all_ok
=
True
# so far
self
.
session
=
session
self
.
session
=
session
self
.
sleep
=
0.01
@dataclass
@dataclass
class
Record
:
class
Record
:
...
@@ -44,21 +48,60 @@ class RecordRetriever:
...
@@ -44,21 +48,60 @@ class RecordRetriever:
async
def
get_record_from_ac_number
(
self
,
ac_number
:
str
)
->
typing
.
Optional
[
Record
]:
async
def
get_record_from_ac_number
(
self
,
ac_number
:
str
)
->
typing
.
Optional
[
Record
]:
# todo timeout error
response
=
await
self
.
session
.
get
(
url
=
self
.
url
,
params
=
{
try
:
'
startRecord
'
:
1
,
await
asyncio
.
sleep
(
self
.
sleep
)
'
maximumRecords
'
:
1
,
response
=
await
self
.
session
.
get
(
url
=
self
.
url
,
params
=
{
'
query
'
:
f
'
alma.local_control_field_009=
{
ac_number
}
'
,
'
startRecord
'
:
1
,
'
version
'
:
'
1.2
'
,
'
maximumRecords
'
:
1
,
'
operation
'
:
'
searchRetrieve
'
,
'
query
'
:
f
'
alma.local_control_field_009=
{
ac_number
}
'
,
'
recordSchema
'
:
'
marcxml
'
,
'
version
'
:
'
1.2
'
,
},
'
operation
'
:
'
searchRetrieve
'
,
timeout
=
5
'
recordSchema
'
:
'
marcxml
'
,
)
},
timeout
=
60
)
except
httpx
.
ConnectTimeout
as
timeout
:
self
.
log
.
append
({
'
error
'
:
'
time_out
'
,
'
message
'
:
str
(
timeout
),
'
ac_number
'
:
ac_number
,
})
return
except
Exception
as
error
:
self
.
sleep
*=
1.3
try
:
await
asyncio
.
sleep
(
self
.
sleep
)
response
=
await
self
.
session
.
get
(
url
=
self
.
url
,
params
=
{
'
startRecord
'
:
1
,
'
maximumRecords
'
:
1
,
'
query
'
:
f
'
alma.local_control_field_009=
{
ac_number
}
'
,
'
version
'
:
'
1.2
'
,
'
operation
'
:
'
searchRetrieve
'
,
'
recordSchema
'
:
'
marcxml
'
,
},
timeout
=
60
)
except
httpx
.
ConnectTimeout
as
timeout
:
self
.
log
.
append
({
'
error
'
:
'
time_out
'
,
'
message
'
:
str
(
timeout
),
'
ac_number
'
:
ac_number
,
})
return
except
Exception
as
error
:
self
.
sleep
*=
1.3
self
.
log
.
append
({
'
error
'
:
'
time_out
'
,
'
message
'
:
str
(
error
),
'
ac_number
'
:
ac_number
,
})
return
sub_log
=
{
sub_log
=
{
'
ac_number
'
:
ac_number
,
'
ac_number
'
:
ac_number
,
'
status_code
'
:
response
.
status_code
,
'
status_code
'
:
response
.
status_code
,
'
url
'
:
response
.
url
.
full_path
,
}
}
if
response
.
status_code
!=
200
:
if
response
.
status_code
!=
200
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment