-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Class has been added to collect articles by months. Time function has…
… been moved into generic module. #111
- Loading branch information
Showing
5 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
######################################################################################################################## | ||
# File "time.py" | ||
# Copyright © Dmitry Morozov 2023 | ||
# Module contains generic functions to work with time intervals. | ||
# If you want to use this file please contact me by dvmorozov@hotmail.com. | ||
######################################################################################################################## | ||
|
||
|
||
import datetime | ||
|
||
|
||
def get_years_range(): | ||
current_date = datetime.datetime.now().date() | ||
current_year = int(current_date.strftime("%Y")) | ||
return range(1985, current_year + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
######################################################################################################################## | ||
# File "month.py" | ||
# Copyright © Dmitry Morozov 2022 | ||
# Class represents single month for aggregating article identifiers. | ||
# If you want to use this file please contact me by dvmorozov@hotmail.com. | ||
######################################################################################################################## | ||
|
||
|
||
from common.time import * | ||
|
||
|
||
months = dict() | ||
month_names = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] | ||
|
||
|
||
class Month(object): | ||
def __init__(self, year, month): | ||
self.year = year | ||
self.month = month | ||
self.article_ids = [] | ||
|
||
def add_article_id(self, article_id): | ||
if article_id not in self.article_ids: | ||
self.article_ids.append(article_id) | ||
|
||
|
||
def create_months(): | ||
global months, month_names | ||
|
||
months.clear() | ||
for year in get_years_range(): | ||
for month in month_names: | ||
month_name = month + '_' + str(year) | ||
months[month_name] = Month(year, month) | ||
|
||
|
||
def get_month(year, month_number): | ||
global month_names | ||
|
||
assert(0 < month_number <= len(month_names)) | ||
|
||
month = month_names[month_number - 1] | ||
month_name = month + '_' + str(year) | ||
return months[month_name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters