-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and refactor into module (#84)
* Refactor to introduce __meta__ file * Add tests and refactor code into a module
- Loading branch information
Showing
17 changed files
with
3,773 additions
and
147 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
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 |
---|---|---|
|
@@ -32,11 +32,11 @@ After gathering a list of birthdays for all the users friends for a full year, i | |
1. Clone repo | ||
`git clone [email protected]:mobeigi/fb2cal.git` | ||
2. Rename `config/config-template.ini` to `config/config.ini` and enter your Facebook email and password (no quotes). | ||
3. Install required python modules | ||
3. Set up pipenv environment | ||
`pipenv install` | ||
4. Run the script manually: | ||
`pipenv run python src/fb2cal.py` | ||
5. Import the created `birthdays.ics` file into Calendar applications (i.e. Google Calendar) | ||
4. Run the `fb2cal` module | ||
`pipenv run python -m fb2cal` | ||
5. Check the output folder (`out` by default) for the created `birthdays.ics` file | ||
|
||
## Configuration | ||
This tool can be configured by editing the `config/config.ini` configuration file. | ||
|
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 |
---|---|---|
@@ -1,28 +1,21 @@ | ||
""" | ||
fb2cal - Facebook Birthday Events to ICS file converter | ||
Created by: mobeigi | ||
This program is free software: you can redistribute it and/or modify it under | ||
the terms of the GNU General Public License as published by the Free Software | ||
Foundation, either version 3 of the License, or (at your option) any later | ||
version. | ||
This program is distributed in the hope that it will be useful, but WITHOUT | ||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along with | ||
this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
|
||
from _version import __version_info__, __version__ | ||
|
||
__author__ = 'Mo Beigi' | ||
__copyright__ = 'Copyright 2019' | ||
__email__ = '[email protected]' | ||
__license__ = "GPLv3" | ||
__maintainer__ = 'Mo Beigi' | ||
__status__ = 'Production' | ||
__website__ = 'https://git.io/fjMwr' | ||
|
||
# Make metadata public to script | ||
__all__ = ['__author__', '__copyright__', '__email__', '__license__', '__maintainer__', '__status__', '__website__', '__version_info__', '__version__'] | ||
""" | ||
fb2cal - Facebook Birthday Events to ICS file converter | ||
Created by: mobeigi | ||
This program is free software: you can redistribute it and/or modify it under | ||
the terms of the GNU General Public License as published by the Free Software | ||
Foundation, either version 3 of the License, or (at your option) any later | ||
version. | ||
This program is distributed in the hope that it will be useful, but WITHOUT | ||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along with | ||
this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
|
||
from .__meta__ import * | ||
from .transformer import * | ||
from .facebook_user import * | ||
from .facebook_browser import * | ||
from .ics_writer import * |
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,96 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
fb2cal - Facebook Birthday Events to ICS file converter | ||
Created by: mobeigi | ||
This program is free software: you can redistribute it and/or modify it under | ||
the terms of the GNU General Public License as published by the Free Software | ||
Foundation, either version 3 of the License, or (at your option) any later | ||
version. | ||
This program is distributed in the hope that it will be useful, but WITHOUT | ||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along with | ||
this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
|
||
import os | ||
import sys | ||
import logging | ||
from distutils import util | ||
|
||
from .ics_writer import ICSWriter | ||
from .logger import Logger | ||
from .config import Config | ||
from .facebook_browser import FacebookBrowser | ||
from .transformer import Transformer | ||
|
||
from .__init__ import __version__, __status__, __website__, __license__ | ||
|
||
# Set CWD to script directory | ||
os.chdir(sys.path[0]) | ||
|
||
# Init logger | ||
logger = Logger('fb2cal').getLogger() | ||
logger.info(f'Starting fb2cal v{__version__} ({__status__}) [{__website__}]') | ||
logger.info(f'This project is released under the {__license__} license.') | ||
|
||
try: | ||
# Read config | ||
logger.info(f'Attemping to parse config file...') | ||
config = Config().getConfig() | ||
logger.info('Config successfully loaded.') | ||
|
||
# Set logging level based on config | ||
try: | ||
logger.setLevel(getattr(logging, config['LOGGING']['level'])) | ||
logging.getLogger().setLevel(logger.level) # Also set root logger level | ||
except AttributeError: | ||
logger.error(f'Invalid logging level specified. Level: {config["LOGGING"]["level"]}') | ||
raise SystemError | ||
|
||
logger.info(f'Logging level set to: {logging.getLevelName(logger.level)}') | ||
|
||
# Init Facebook browser | ||
facebook_browser = FacebookBrowser() | ||
|
||
# Attempt login | ||
logger.info('Attemping to authenticate with Facebook...') | ||
facebook_browser.authenticate(config['AUTH']['FB_EMAIL'], config['AUTH']['FB_PASS']) | ||
logger.info('Successfully authenticated with Facebook.') | ||
|
||
# Fetch birthdays for a full calendar year and transform them | ||
facebook_users = [] | ||
transformer = Transformer() | ||
|
||
# Endpoint will return all birthdays for offset_month plus the following 2 consecutive months. | ||
logger.info('Fetching all Birthdays via BirthdayCometRootQuery endpoint...') | ||
for offset_month in [1, 4, 7, 10]: | ||
birthday_comet_root_json = facebook_browser.query_graph_ql_birthday_comet_root(offset_month) | ||
facebook_users_for_quarter = transformer.transform_birthday_comet_root_to_birthdays(birthday_comet_root_json) | ||
facebook_users.extend(facebook_users_for_quarter) | ||
|
||
if len(facebook_users) == 0: | ||
logger.warning(f'Facebook user list is empty. Failed to fetch any birthdays.') | ||
raise SystemError | ||
|
||
logger.info(f'A total of {len(facebook_users)} birthdays were found.') | ||
|
||
# Generate ICS | ||
ics_writer = ICSWriter(facebook_users) | ||
logger.info('Creating birthday ICS file...') | ||
ics_writer.generate() | ||
logger.info('ICS file created successfully.') | ||
|
||
# Save to file system | ||
if util.strtobool(config['FILESYSTEM']['SAVE_TO_FILE']): | ||
ics_writer.write(config['FILESYSTEM']['ICS_FILE_PATH']) | ||
|
||
logger.info('Done! Terminating gracefully.') | ||
except SystemExit: | ||
logger.critical(f'Critical error encountered. Terminating.') | ||
sys.exit() | ||
finally: | ||
logging.shutdown() |
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,13 @@ | ||
__author__ = 'Mo Beigi' | ||
__copyright__ = 'Copyright 2019-2020' | ||
__email__ = '[email protected]' | ||
__license__ = "GPLv3" | ||
__maintainer__ = 'Mo Beigi' | ||
__status__ = 'Production' | ||
__website__ = 'https://git.io/fjMwr' | ||
__version_info__ = (1, 2, 0) | ||
__version__ = '.'.join(map(str, __version_info__)) | ||
|
||
|
||
# Make metadata public to script | ||
__all__ = ['__author__', '__copyright__', '__email__', '__license__', '__maintainer__', '__status__', '__website__', '__version_info__', '__version__'] |
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
File renamed without changes.
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.