Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trv-crawl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nils Breyer
trv-crawl
Commits
c8cdb6b1
Commit
c8cdb6b1
authored
2 years ago
by
Nils Breyer
Browse files
Options
Downloads
Patches
Plain Diff
support TrainAnnouncement schema 1.8
parent
e6414854
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+11
-4
11 additions, 4 deletions
CHANGELOG.md
README.md
+4
-4
4 additions, 4 deletions
README.md
crawl.py
+5
-12
5 additions, 12 deletions
crawl.py
crawler/trafikverket.py
+5
-4
5 additions, 4 deletions
crawler/trafikverket.py
with
25 additions
and
24 deletions
CHANGELOG.md
+
11
−
4
View file @
c8cdb6b1
# Changelog
## 1.1.2 (2022-01-26)
## 1.2.0 (2023-02-16)
*
NEW: Collect new column DepartureDateOTN for announcements (schema 1.8)
*
CHANGED: TechnicalDateTime renamed to LocationDateTimeOTN (schema 1.8)
*
CHANGED: TechnicalTrainIdent renamed to OperationalTrainNumber (schema 1.8)
*
REMOVED: --compress flag (was not implemented anyway)
## 1.1.2 (2023-01-26)
*
FIX: Simultaneous writes to csv can cause invalid format in output file
## 1.1.1 (202
2
-01-13)
## 1.1.1 (202
3
-01-13)
*
FIX: Connection not initialized if status file unreadable
## 1.1.0 (202
2
-01-13)
## 1.1.0 (202
3
-01-13)
*
NEW: Warn on low disk space
## 1.0.0 (202
2
-01-13)
## 1.0.0 (202
3
-01-13)
*
NEW: Create output directory if not existing
...
...
This diff is collapsed.
Click to expand it.
README.md
+
4
−
4
View file @
c8cdb6b1
...
...
@@ -3,17 +3,16 @@
Crawler for Trafikverkets API
```
usage: crawl.py [-h] [-s]
[-c]
[-f] -l locationSignature [-o path] [-w webhookurl] [-a authkey] [-v] objecttype
usage: crawl.py [-h] [-s] [-f] -l locationSignature [-o path] [-w webhookurl] [-a authkey] [-v]
[-q]
objecttype
Crawler for Trafikverket's Trafikinfo API
Crawler for Trafikverket's Trafikinfo API
- version 1.2.0
positional arguments:
objecttype the API objecttype to crawl
option
al argument
s:
options:
-h, --help show this help message and exit
-s, --stream use streaming in real-time instead of daily crawling
-c, --compress write zip compressed csv files
-f, --force force new connection instead of reconnecting
-l locationSignature, --locationSignature locationSignature
the location signature of the station to crawl data for
...
...
@@ -24,6 +23,7 @@ optional arguments:
-a authkey, --authkey authkey
The API authkey to use as obtained from https://api.trafikinfo.trafikverket.se/Account/Register
-v, --verbose Prints extra debug information
-q, --query Print query only instead of starting a crawler
```
*Example:*
...
...
This diff is collapsed.
Click to expand it.
crawl.py
+
5
−
12
View file @
c8cdb6b1
...
...
@@ -12,7 +12,7 @@ from crawler import StreamCrawler
import
crawler.trafikverket
VERSION
=
"
1.
1.2
"
VERSION
=
"
1.
2.0
"
parser
=
argparse
.
ArgumentParser
(
description
=
"
Crawler for Trafikverket
'
s Trafikinfo API - version
"
+
VERSION
)
...
...
@@ -28,10 +28,10 @@ parser.add_argument('-s', '--stream',
help
=
'
use streaming in real-time instead of daily crawling
'
)
parser
.
add_argument
(
'
-c
'
,
'
--compress
'
,
action
=
'
store_true
'
,
help
=
'
write zip compressed csv files
'
)
#
parser.add_argument('-c', '--compress',
#
action='store_true',
#
help='write zip compressed csv files'
#
)
parser
.
add_argument
(
'
-f
'
,
'
--force
'
,
action
=
'
store_true
'
,
...
...
@@ -86,8 +86,6 @@ if args.output is None:
else
:
#specified, check if exists
if
not
os
.
path
.
isdir
(
args
.
output
):
print
(
"
The output path {output} does not exist and will be created.
"
.
format
(
output
=
args
.
output
))
try
:
os
.
makedirs
(
args
.
output
)
print
(
"
The output path {output} has been created.
"
.
format
(
output
=
args
.
output
))
...
...
@@ -132,11 +130,6 @@ elif args.objecttype == "TrainMessage" and not args.stream:
if
not
args
.
webhook
is
None
:
c
.
message_webhook_url
=
args
.
webhook
c
.
compress
=
args
.
compress
if
c
.
compress
:
print
(
"
Compression not supported yet.
"
)
if
args
.
verbose
:
c
.
DEBUG
=
True
print
(
"
Verbose output enabled.
"
)
...
...
This diff is collapsed.
Click to expand it.
crawler/trafikverket.py
+
5
−
4
View file @
c8cdb6b1
...
...
@@ -38,8 +38,8 @@ COLUMNS_TRAINANNOUNCEMENT = [
"
ProductInformation
"
,
"
ScheduledDepartureDateTime
"
,
"
Service
"
,
"
Technical
DateTime
"
,
"
Technic
alTrain
Ident
"
,
"
Location
DateTime
OTN
"
,
"
Operation
alTrain
Number
"
,
"
TimeAtLocation
"
,
"
TimeAtLocationWithSeconds
"
,
"
ToLocation
"
,
...
...
@@ -50,7 +50,8 @@ COLUMNS_TRAINANNOUNCEMENT = [
"
WebLink
"
,
"
WebLinkName
"
,
"
ViaFromLocation
"
,
"
ViaToLocation
"
"
ViaToLocation
"
,
"
DepartureDateOTN
"
]
COLUMNS_TRAINMESSAGE
=
[
...
...
@@ -110,7 +111,7 @@ def build_query(authkey, attributes = {}, filter = "", columns = []):
def
get_train_announcement_query
(
authkey
,
startTime
=
None
,
endTime
=
None
,
locationSignature
=
""
,
sseurl
=
False
,
limit
=
None
):
attributes
=
{
"
objecttype
"
:
"
TrainAnnouncement
"
,
"
schemaversion
"
:
"
1.
6
"
,
"
schemaversion
"
:
"
1.
8
"
,
"
orderby
"
:
"
TimeAtLocation
"
,
"
includedeletedobjects
"
:
"
true
"
,
"
sseurl
"
:
sseurl
...
...
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