Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ru-bot-twitter
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
CAAD
ru-bot-twitter
Commits
f85e6af7
Commit
f85e6af7
authored
3 years ago
by
fmk17
Browse files
Options
Downloads
Patches
Plain Diff
Update crawler
parent
e86b6586
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.pre-commit-config.yaml
+1
-1
1 addition, 1 deletion
.pre-commit-config.yaml
crawler.py
+9
-1
9 additions, 1 deletion
crawler.py
with
10 additions
and
2 deletions
.pre-commit-config.yaml
+
1
−
1
View file @
f85e6af7
...
...
@@ -7,7 +7,7 @@ repos:
-
id
:
trailing-whitespace
# Black formats the Python code
-
repo
:
https://github.com/psf/black
rev
:
22.
1
.0
rev
:
22.
3
.0
hooks
:
-
id
:
black
# Flake8 lints the Python code
...
...
This diff is collapsed.
Click to expand it.
crawler.py
+
9
−
1
View file @
f85e6af7
import
logging
import
re
from
collections
import
namedtuple
from
datetime
import
date
,
datetime
,
timedelta
from
itertools
import
dropwhile
from
typing
import
Dict
,
List
,
Set
import
requests
...
...
@@ -15,6 +17,9 @@ LocationDays = namedtuple("LocationDays", "days, location, update_datetime")
cached_update_times
:
Dict
[
Location
,
datetime
]
=
dict
()
cached_responses
:
Dict
[
Location
,
LocationDays
]
=
dict
()
DATE_REGEX
=
r
"
: (\d{1,2})\/(\d{1,2})\/(\d{4})
"
logger
=
logging
.
getLogger
(
"
crawler
"
)
def
get_location_days
(
location
:
Location
,
menu_item_indicators
:
List
[
MenuItemIndicator
]
...
...
@@ -35,12 +40,15 @@ def get_location_days(
post
=
soup
.
select_one
(
"
#post div:nth-child(3)
"
)
post_children
=
iter
(
post
.
children
)
post_children
=
(
node
for
node
in
post_children
if
node
.
text
.
strip
()
!=
""
)
post_children
=
dropwhile
(
lambda
n
:
not
re
.
search
(
DATE_REGEX
,
n
.
text
),
post_children
)
days
=
[]
for
date_node
,
table_node
in
zip
(
post_children
,
post_children
):
date_text
=
date_node
.
text
date_re
=
re
.
search
(
r
"
(\d{1,2})\/(\d{1,2})\/(\d{4})
"
,
date_text
)
date_re
=
re
.
search
(
DATE_REGEX
,
date_text
)
if
date_re
is
None
:
break
d
,
m
,
y
=
map
(
int
,
date_re
.
groups
())
...
...
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