Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ru-bot-telegram
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
Harbor 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-telegram
Commits
0504e191
Commit
0504e191
authored
2 years ago
by
fmk17
Browse files
Options
Downloads
Patches
Plain Diff
Fix two digit year and timezone issues
parent
56523ccc
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
crawler.py
+6
-2
6 additions, 2 deletions
crawler.py
main.py
+3
-2
3 additions, 2 deletions
main.py
with
9 additions
and
4 deletions
crawler.py
+
6
−
2
View file @
0504e191
...
...
@@ -17,7 +17,7 @@ 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})
"
DATE_REGEX
=
r
"
: (\d{1,2})\/(\d{1,2})\/(\d{
2,
4})
"
logger
=
logging
.
getLogger
(
"
crawler
"
)
...
...
@@ -52,6 +52,8 @@ def get_location_days(
if
date_re
is
None
:
break
d
,
m
,
y
=
map
(
int
,
date_re
.
groups
())
if
y
<
100
:
y
+=
2000
table_children
=
iter
(
table_node
.
select
(
"
td
"
))
menus
=
[]
for
title_node
,
item_nodes
in
zip
(
table_children
,
table_children
):
...
...
@@ -90,7 +92,9 @@ def get_location_days(
name
=
item_name
,
indicators
=
frozenset
(
item_indicators
)
)
)
menus
.
append
(
Menu
(
meal_name
=
title_node
.
text
,
items
=
tuple
(
items
)))
menus
.
append
(
Menu
(
meal_name
=
title_node
.
text
.
strip
(),
items
=
tuple
(
items
))
)
days
.
append
(
Day
(
date
=
date
(
y
,
m
,
d
),
date_raw
=
date_text
,
menus
=
menus
))
cached_update_times
[
location
]
=
datetime
.
now
()
...
...
This diff is collapsed.
Click to expand it.
main.py
+
3
−
2
View file @
0504e191
...
...
@@ -28,6 +28,7 @@ from telegram.ext import (
from
crawler
import
Day
,
Location
,
LocationDays
,
get_location_days
from
database
import
(
CURITIBA_TZ
,
delete_all_schedules_from_user
,
delete_menu_item_indicator_preference
,
delete_schedule_by_key
,
...
...
@@ -125,7 +126,7 @@ def format_location_days(location_days, visible_menu_item_indicators):
strings
.
append
(
"
<i>Atualizado às
"
+
update_datetime
.
strftime
(
"
%H:%M:%S
"
)
+
update_datetime
.
astimezone
(
CURITIBA_TZ
).
strftime
(
"
%H:%M:%S
"
)
+
"
de hoje</i>
"
)
return
"
\n\n
"
.
join
(
strings
)
...
...
@@ -862,7 +863,7 @@ def try_send_schedule_again(context: CallbackContext) -> None:
def
send_scheduled
(
context
:
CallbackContext
)
->
None
:
dt
=
datetime
.
now
()
dt
=
datetime
.
now
(
tz
=
CURITIBA_TZ
)
dt
+=
timedelta
(
minutes
=
EVERY_X_MINUTES
/
2
)
dt
-=
timedelta
(
minutes
=
dt
.
minute
%
EVERY_X_MINUTES
,
...
...
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