fb2cal-fork 2.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fb2cal/__init__.py +19 -0
- fb2cal/__main__.py +189 -0
- fb2cal/__meta__.py +41 -0
- fb2cal/contact.py +46 -0
- fb2cal/errors.py +41 -0
- fb2cal/facebook_client.py +89 -0
- fb2cal/facebook_queries.py +60 -0
- fb2cal/facebook_session.py +101 -0
- fb2cal/facebook_token.py +31 -0
- fb2cal/ics_writer.py +109 -0
- fb2cal/json_exporter.py +38 -0
- fb2cal/logger.py +28 -0
- fb2cal/pipeline.py +48 -0
- fb2cal/text_format.py +32 -0
- fb2cal/transformer.py +47 -0
- fb2cal/utils.py +12 -0
- fb2cal/vcard_exporter.py +90 -0
- fb2cal_fork-2.0.1.dist-info/METADATA +240 -0
- fb2cal_fork-2.0.1.dist-info/RECORD +23 -0
- fb2cal_fork-2.0.1.dist-info/WHEEL +5 -0
- fb2cal_fork-2.0.1.dist-info/entry_points.txt +2 -0
- fb2cal_fork-2.0.1.dist-info/licenses/LICENSE +674 -0
- fb2cal_fork-2.0.1.dist-info/top_level.txt +1 -0
fb2cal/ics_writer.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import calendar
|
|
2
|
+
import os
|
|
3
|
+
from datetime import datetime, timedelta, timezone
|
|
4
|
+
|
|
5
|
+
from dateutil.relativedelta import relativedelta
|
|
6
|
+
from ics import Calendar, Event
|
|
7
|
+
from ics.grammar.parse import ContentLine
|
|
8
|
+
|
|
9
|
+
from .__init__ import __github_short_url__, __status__, __version__
|
|
10
|
+
from .logger import Logger
|
|
11
|
+
from .text_format import serialize_content_lines
|
|
12
|
+
from .utils import generate_facebook_profile_url_permalink
|
|
13
|
+
|
|
14
|
+
""" Write Birthdays to an ICS file """
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ICSWriter:
|
|
18
|
+
def __init__(self, contacts):
|
|
19
|
+
self.logger = Logger("fb2cal").getLogger()
|
|
20
|
+
self.contacts = contacts
|
|
21
|
+
|
|
22
|
+
def generate(self):
|
|
23
|
+
c = Calendar()
|
|
24
|
+
c.scale = "GREGORIAN"
|
|
25
|
+
c.method = "PUBLISH"
|
|
26
|
+
c.creator = f"fb2cal v{__version__} ({__status__}) [{__github_short_url__}]"
|
|
27
|
+
c.extra.append(
|
|
28
|
+
ContentLine(name="X-WR-CALNAME", value="Facebook Birthdays (fb2cal)")
|
|
29
|
+
)
|
|
30
|
+
c.extra.append(ContentLine(name="X-PUBLISHED-TTL", value="PT12H"))
|
|
31
|
+
c.extra.append(ContentLine(name="X-ORIGINAL-URL", value="/events/birthdays/"))
|
|
32
|
+
|
|
33
|
+
# Keep the existing naive date representation while making the clock
|
|
34
|
+
# source explicit and deterministic across host time zones.
|
|
35
|
+
cur_date = datetime.now(timezone.utc).replace(tzinfo=None)
|
|
36
|
+
|
|
37
|
+
for contact in self.contacts:
|
|
38
|
+
# Don't add extra 's' if name already ends with 's'
|
|
39
|
+
formatted_username = (
|
|
40
|
+
f"{contact.name}'s" if contact.name[-1] != "s" else f"{contact.name}'"
|
|
41
|
+
)
|
|
42
|
+
formatted_username = f"{formatted_username} Birthday"
|
|
43
|
+
|
|
44
|
+
# Set date components
|
|
45
|
+
day = contact.birthday_day
|
|
46
|
+
month = contact.birthday_month
|
|
47
|
+
year = contact.birthday_year
|
|
48
|
+
|
|
49
|
+
# The birth year may not be visible due to privacy settings
|
|
50
|
+
# In this case, calculate the year as this year or next year based on if its past current month or not
|
|
51
|
+
if year is None:
|
|
52
|
+
year = (
|
|
53
|
+
cur_date.year
|
|
54
|
+
if contact.birthday_month >= cur_date.month
|
|
55
|
+
else (cur_date + relativedelta(years=1)).year
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Feb 29 special case:
|
|
59
|
+
# If event year is not a leap year, use Feb 28 as birthday date instead
|
|
60
|
+
if (
|
|
61
|
+
contact.birthday_month == 2
|
|
62
|
+
and contact.birthday_day == 29
|
|
63
|
+
and not calendar.isleap(year)
|
|
64
|
+
):
|
|
65
|
+
day = 28
|
|
66
|
+
|
|
67
|
+
# Format date components as needed
|
|
68
|
+
month = f"{month:02}"
|
|
69
|
+
day = f"{day:02}"
|
|
70
|
+
|
|
71
|
+
# Event meta data
|
|
72
|
+
e = Event()
|
|
73
|
+
|
|
74
|
+
e.uid = contact.id
|
|
75
|
+
e.name = formatted_username
|
|
76
|
+
e.created = cur_date
|
|
77
|
+
e.description = (
|
|
78
|
+
f"{contact}\n{generate_facebook_profile_url_permalink(contact)}"
|
|
79
|
+
)
|
|
80
|
+
e.begin = f"{year}-{month}-{day} 00:00:00"
|
|
81
|
+
e.make_all_day()
|
|
82
|
+
e.duration = timedelta(days=1)
|
|
83
|
+
e.extra.append(ContentLine(name="RRULE", value="FREQ=YEARLY"))
|
|
84
|
+
|
|
85
|
+
c.events.add(e)
|
|
86
|
+
|
|
87
|
+
self.birthday_calendar = c
|
|
88
|
+
|
|
89
|
+
def write(self, ics_file_path):
|
|
90
|
+
ics_str = self.export()
|
|
91
|
+
|
|
92
|
+
self.logger.info("Saving ICS file to local file system...")
|
|
93
|
+
|
|
94
|
+
directory = os.path.dirname(ics_file_path)
|
|
95
|
+
if directory and not os.path.exists(directory):
|
|
96
|
+
os.makedirs(directory, exist_ok=True)
|
|
97
|
+
|
|
98
|
+
with open(ics_file_path, mode="w", encoding="UTF-8") as ics_file:
|
|
99
|
+
ics_file.write(ics_str)
|
|
100
|
+
os.chmod(ics_file_path, 0o600)
|
|
101
|
+
self.logger.info(
|
|
102
|
+
f"Successfully saved ICS file to {os.path.abspath(ics_file_path)}"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
def export(self):
|
|
106
|
+
return serialize_content_lines(self.birthday_calendar)
|
|
107
|
+
|
|
108
|
+
def get_birthday_calendar(self):
|
|
109
|
+
return self.birthday_calendar
|
fb2cal/json_exporter.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Canonical JSON interchange/debug exporter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Iterable
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .contact import BirthdayContact
|
|
11
|
+
from .pipeline import summarize_contacts
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class JSONExporter:
|
|
15
|
+
def __init__(
|
|
16
|
+
self, contacts: Iterable[BirthdayContact], extracted_at: str | None = None
|
|
17
|
+
):
|
|
18
|
+
self.contacts = list(contacts)
|
|
19
|
+
self.extracted_at = extracted_at or datetime.now(timezone.utc).isoformat()
|
|
20
|
+
|
|
21
|
+
def to_dict(self) -> dict:
|
|
22
|
+
summary = summarize_contacts(self.contacts)
|
|
23
|
+
return {
|
|
24
|
+
"version": 1,
|
|
25
|
+
"source": "facebook",
|
|
26
|
+
"extracted_at": self.extracted_at,
|
|
27
|
+
"summary": summary.to_dict(),
|
|
28
|
+
"contacts": [contact.to_dict() for contact in self.contacts],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def export(self) -> str:
|
|
32
|
+
return json.dumps(self.to_dict(), ensure_ascii=False, indent=2) + "\n"
|
|
33
|
+
|
|
34
|
+
def write(self, path: str | Path) -> None:
|
|
35
|
+
target = Path(path)
|
|
36
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
37
|
+
target.write_text(self.export(), encoding="utf-8")
|
|
38
|
+
target.chmod(0o600)
|
fb2cal/logger.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import atexit
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
LOGGING_FILE_PATH = "logs/fb2cal.log"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Logger:
|
|
9
|
+
def __init__(self, name):
|
|
10
|
+
# Setup logger
|
|
11
|
+
if not os.path.exists(os.path.dirname(LOGGING_FILE_PATH)):
|
|
12
|
+
os.makedirs(os.path.dirname(LOGGING_FILE_PATH), exist_ok=True)
|
|
13
|
+
|
|
14
|
+
if not logging.getLogger().handlers:
|
|
15
|
+
logging.basicConfig(
|
|
16
|
+
format="[%(asctime)s] %(name)s %(levelname)s (%(funcName)s) %(message)s",
|
|
17
|
+
level=logging.INFO,
|
|
18
|
+
handlers=[
|
|
19
|
+
logging.StreamHandler(),
|
|
20
|
+
logging.FileHandler(LOGGING_FILE_PATH, encoding="UTF-8"),
|
|
21
|
+
],
|
|
22
|
+
)
|
|
23
|
+
atexit.register(logging.shutdown)
|
|
24
|
+
|
|
25
|
+
self.logger = logging.getLogger(name)
|
|
26
|
+
|
|
27
|
+
def getLogger(self):
|
|
28
|
+
return self.logger
|
fb2cal/pipeline.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Extraction pipeline shared by CLI and programmatic callers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from .facebook_client import FacebookClient
|
|
9
|
+
from .transformer import Transformer
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class ExtractionSummary:
|
|
14
|
+
"""Counts that can be derived from the birthday query itself."""
|
|
15
|
+
|
|
16
|
+
contacts: int
|
|
17
|
+
with_year: int
|
|
18
|
+
without_year: int
|
|
19
|
+
|
|
20
|
+
def to_dict(self) -> dict[str, int]:
|
|
21
|
+
return {
|
|
22
|
+
"contacts": self.contacts,
|
|
23
|
+
"with_year": self.with_year,
|
|
24
|
+
"without_year": self.without_year,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def extract_birthdays(client: FacebookClient, offsets: Iterable[int] = (0, 3, 6, 9)):
|
|
29
|
+
"""Fetch, transform, and deduplicate birthday contacts by Facebook ID."""
|
|
30
|
+
transformer = Transformer()
|
|
31
|
+
contacts = {}
|
|
32
|
+
for offset_month in offsets:
|
|
33
|
+
result = client.query_graph_ql_birthday_comet_monthly(offset_month)
|
|
34
|
+
for contact in transformer.transform_birthday_comet_monthly_to_birthdays(
|
|
35
|
+
result
|
|
36
|
+
):
|
|
37
|
+
contacts[contact.id] = contact
|
|
38
|
+
return sorted(contacts.values())
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def summarize_contacts(contacts) -> ExtractionSummary:
|
|
42
|
+
contacts = list(contacts)
|
|
43
|
+
with_year = sum(contact.birthday_year is not None for contact in contacts)
|
|
44
|
+
return ExtractionSummary(
|
|
45
|
+
contacts=len(contacts),
|
|
46
|
+
with_year=with_year,
|
|
47
|
+
without_year=len(contacts) - with_year,
|
|
48
|
+
)
|
fb2cal/text_format.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Helpers for serializing CRLF-delimited text formats."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def fold_content_line(line: str, max_octets: int = 75) -> str:
|
|
9
|
+
"""Fold one UTF-8 content line without splitting a multi-byte character."""
|
|
10
|
+
if max_octets < 2:
|
|
11
|
+
raise ValueError("max_octets must be at least 2")
|
|
12
|
+
|
|
13
|
+
chunks: list[str] = []
|
|
14
|
+
current = ""
|
|
15
|
+
for character in line:
|
|
16
|
+
candidate = current + character
|
|
17
|
+
if current and len(candidate.encode("utf-8")) > max_octets:
|
|
18
|
+
chunks.append(current)
|
|
19
|
+
current = " " + character
|
|
20
|
+
else:
|
|
21
|
+
current = candidate
|
|
22
|
+
chunks.append(current)
|
|
23
|
+
return "\r\n".join(chunks)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def serialize_content_lines(lines: Iterable[str]) -> str:
|
|
27
|
+
"""Fold and serialize content lines with RFC-style CRLF terminators."""
|
|
28
|
+
serialized = []
|
|
29
|
+
for line in lines:
|
|
30
|
+
serialized.append(fold_content_line(line.rstrip("\r\n")))
|
|
31
|
+
serialized.append("\r\n")
|
|
32
|
+
return "".join(serialized)
|
fb2cal/transformer.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from .contact import BirthdayContact
|
|
2
|
+
from .errors import GraphQLSchemaError
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Transformer:
|
|
6
|
+
def transform_birthday_comet_monthly_to_birthdays(self, birthday_comet_root_json):
|
|
7
|
+
"""Transform BirthdayCometMonthlyBirthdaysRefetchQuery into contacts."""
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
edges = birthday_comet_root_json["data"]["viewer"][
|
|
11
|
+
"all_friends_by_birthday_month"
|
|
12
|
+
]["edges"]
|
|
13
|
+
except (KeyError, TypeError) as exc:
|
|
14
|
+
raise GraphQLSchemaError(
|
|
15
|
+
"Facebook birthday response is missing all_friends_by_birthday_month.edges"
|
|
16
|
+
) from exc
|
|
17
|
+
if not isinstance(edges, list):
|
|
18
|
+
raise GraphQLSchemaError("Facebook birthday edges is not a list")
|
|
19
|
+
|
|
20
|
+
contacts = []
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
for all_friends_by_birthday_month_edge in edges:
|
|
24
|
+
for friend_edge in all_friends_by_birthday_month_edge["node"][
|
|
25
|
+
"friends"
|
|
26
|
+
]["edges"]:
|
|
27
|
+
friend = friend_edge["node"]
|
|
28
|
+
birthdate = friend["birthdate"]
|
|
29
|
+
picture = friend.get("profile_picture") or {}
|
|
30
|
+
|
|
31
|
+
contacts.append(
|
|
32
|
+
BirthdayContact(
|
|
33
|
+
friend["id"],
|
|
34
|
+
friend["name"],
|
|
35
|
+
friend.get("profile_url"),
|
|
36
|
+
picture.get("uri"),
|
|
37
|
+
birthdate["day"],
|
|
38
|
+
birthdate["month"],
|
|
39
|
+
birthdate.get("year"),
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
except (KeyError, TypeError) as exc:
|
|
43
|
+
raise GraphQLSchemaError(
|
|
44
|
+
"Facebook birthday response has an unexpected friend schema"
|
|
45
|
+
) from exc
|
|
46
|
+
|
|
47
|
+
return contacts
|
fb2cal/utils.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .contact import BirthdayContact
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def generate_facebook_profile_url_permalink(contact: BirthdayContact) -> str:
|
|
5
|
+
"""Build a stable Facebook profile URL from a contact ID."""
|
|
6
|
+
return f"https://www.facebook.com/{contact.id}"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Facebook prepends an infinite while loop to their API responses as anti hijacking protection
|
|
10
|
+
# It must be stripped away before parsing a response as JSON
|
|
11
|
+
def remove_anti_hijacking_protection(text: str) -> str:
|
|
12
|
+
return text.removeprefix("for (;;);")
|
fb2cal/vcard_exporter.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Interoperable vCard exporter with 4.0 and legacy 3.0 output."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Literal
|
|
8
|
+
|
|
9
|
+
from .contact import BirthdayContact
|
|
10
|
+
from .text_format import serialize_content_lines
|
|
11
|
+
|
|
12
|
+
VCardVersion = Literal["3.0", "4.0"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _escape_text(value: str | None) -> str:
|
|
16
|
+
if not value:
|
|
17
|
+
return ""
|
|
18
|
+
return (
|
|
19
|
+
value.replace("\\", "\\\\")
|
|
20
|
+
.replace(";", "\\;")
|
|
21
|
+
.replace(",", "\\,")
|
|
22
|
+
.replace("\r\n", "\n")
|
|
23
|
+
.replace("\r", "\n")
|
|
24
|
+
.replace("\n", "\\n")
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _sanitize_uri(value: str | None) -> str:
|
|
29
|
+
if not value:
|
|
30
|
+
return ""
|
|
31
|
+
return value.replace("\r", "").replace("\n", "")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class VCardExporter:
|
|
35
|
+
def __init__(
|
|
36
|
+
self, contacts: Iterable[BirthdayContact], version: VCardVersion = "4.0"
|
|
37
|
+
):
|
|
38
|
+
if version not in ("3.0", "4.0"):
|
|
39
|
+
raise ValueError(f"Unsupported vCard version: {version}")
|
|
40
|
+
self.contacts = list(contacts)
|
|
41
|
+
self.version = version
|
|
42
|
+
|
|
43
|
+
def export(self) -> str:
|
|
44
|
+
lines = []
|
|
45
|
+
for contact in self.contacts:
|
|
46
|
+
if self.version == "4.0":
|
|
47
|
+
birthday = (
|
|
48
|
+
f"{contact.birthday_year:04}{contact.birthday_month:02}{contact.birthday_day:02}"
|
|
49
|
+
if contact.birthday_year is not None
|
|
50
|
+
else f"--{contact.birthday_month:02}{contact.birthday_day:02}"
|
|
51
|
+
)
|
|
52
|
+
else:
|
|
53
|
+
birthday = (
|
|
54
|
+
f"{contact.birthday_year:04}-{contact.birthday_month:02}-{contact.birthday_day:02}"
|
|
55
|
+
if contact.birthday_year is not None
|
|
56
|
+
else f"--{contact.birthday_month:02}-{contact.birthday_day:02}"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
lines.extend(
|
|
60
|
+
[
|
|
61
|
+
"BEGIN:VCARD",
|
|
62
|
+
f"VERSION:{self.version}",
|
|
63
|
+
f"UID:fb2cal-facebook-{_escape_text(contact.id)}",
|
|
64
|
+
f"FN:{_escape_text(contact.name)}",
|
|
65
|
+
f"N:{_escape_text(contact.name)};;;;",
|
|
66
|
+
f"BDAY:{birthday}",
|
|
67
|
+
]
|
|
68
|
+
)
|
|
69
|
+
if contact.profile_url:
|
|
70
|
+
lines.append(f"URL;TYPE=Facebook:{_sanitize_uri(contact.profile_url)}")
|
|
71
|
+
if contact.picture_url:
|
|
72
|
+
photo = (
|
|
73
|
+
f"PHOTO;VALUE=URI:{_sanitize_uri(contact.picture_url)}"
|
|
74
|
+
if self.version == "3.0"
|
|
75
|
+
else f"PHOTO:{_sanitize_uri(contact.picture_url)}"
|
|
76
|
+
)
|
|
77
|
+
lines.append(photo)
|
|
78
|
+
lines.extend(
|
|
79
|
+
[
|
|
80
|
+
"X-FB2CAL-SOURCE:facebook",
|
|
81
|
+
"END:VCARD",
|
|
82
|
+
]
|
|
83
|
+
)
|
|
84
|
+
return serialize_content_lines(lines)
|
|
85
|
+
|
|
86
|
+
def write(self, path: str | Path) -> None:
|
|
87
|
+
target = Path(path)
|
|
88
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
89
|
+
target.write_text(self.export(), encoding="utf-8", newline="")
|
|
90
|
+
target.chmod(0o600)
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fb2cal-fork
|
|
3
|
+
Version: 2.0.1
|
|
4
|
+
Summary: Maintained fork of fb2cal for exporting Facebook birthdays to calendar and contact files
|
|
5
|
+
Author: Alessandro Digilio
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/alsd4git/fb2cal
|
|
8
|
+
Project-URL: Repository, https://github.com/alsd4git/fb2cal
|
|
9
|
+
Project-URL: Upstream, https://github.com/mobeigi/fb2cal
|
|
10
|
+
Keywords: facebook,birthday,calendar,export,ics
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Other Audience
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: certifi>=2026.10.18
|
|
23
|
+
Requires-Dist: ics>=0.7.2
|
|
24
|
+
Requires-Dist: requests>=2.31.0
|
|
25
|
+
Requires-Dist: urllib3>=2.8.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# fb2cal
|
|
29
|
+
|
|
30
|
+
Export Facebook birthdays to calendar and contact files.
|
|
31
|
+
|
|
32
|
+
[](https://github.com/alsd4git/fb2cal/actions/workflows/test-fb2cal.yml)
|
|
33
|
+
[](https://github.com/alsd4git/fb2cal/releases)
|
|
34
|
+
[](https://github.com/alsd4git/fb2cal/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
This repository is a maintained fork of [mobeigi/fb2cal](https://github.com/mobeigi/fb2cal).
|
|
37
|
+
The upstream project is preserved as a reference and as a possible source of focused upstream
|
|
38
|
+
contributions.
|
|
39
|
+
|
|
40
|
+
## What it does
|
|
41
|
+
|
|
42
|
+
Facebook no longer provides the original birthday calendar export. fb2cal reads the authenticated
|
|
43
|
+
birthday page session and queries the same birthday data used by Facebook's web interface. It
|
|
44
|
+
deduplicates the visible birthdays for a full year and exports them as:
|
|
45
|
+
|
|
46
|
+
- ICS calendar events for Google Calendar, Apple Calendar, and similar clients;
|
|
47
|
+
- JSON contact data for automation and inspection;
|
|
48
|
+
- vCard 4.0 contacts for address-book imports, with a vCard 3.0 compatibility mode for older
|
|
49
|
+
clients.
|
|
50
|
+
|
|
51
|
+
The export includes only birthdays visible to the authenticated Facebook account. A total profile
|
|
52
|
+
friend count is not available in the birthday query and is intentionally not fetched through a
|
|
53
|
+
fragile profile-page scrape.
|
|
54
|
+
|
|
55
|
+
## Requirements
|
|
56
|
+
|
|
57
|
+
- An authenticated Facebook account;
|
|
58
|
+
- Python 3.10 or newer;
|
|
59
|
+
- [uv](https://docs.astral.sh/uv/).
|
|
60
|
+
|
|
61
|
+
The command never scans browser profiles or decrypts browser databases. It requires an explicit
|
|
62
|
+
JSON export of the cookies from a browser session that is already logged in to Facebook.
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
Install the exact wheel published with the tagged GitHub Release:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
uv tool install https://github.com/alsd4git/fb2cal/releases/download/v2.0.1/fb2cal_fork-2.0.1-py3-none-any.whl
|
|
70
|
+
fb2cal --help
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For a one-off run without keeping the tool installed:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
uvx --from https://github.com/alsd4git/fb2cal/releases/download/v2.0.1/fb2cal_fork-2.0.1-py3-none-any.whl fb2cal --help
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`pip` can install the same wheel when preferred:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python -m pip install https://github.com/alsd4git/fb2cal/releases/download/v2.0.1/fb2cal_fork-2.0.1-py3-none-any.whl
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The examples select the exact fb2cal wheel from a concrete release. Its dependencies are still
|
|
86
|
+
resolved by the installer; use a checkout with `uv sync --locked` for the development dependency
|
|
87
|
+
versions recorded in `uv.lock`. When selecting another release, copy the exact wheel URL from its
|
|
88
|
+
GitHub Release page.
|
|
89
|
+
|
|
90
|
+
## Quick start
|
|
91
|
+
|
|
92
|
+
Validate an exported browser session:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
fb2cal doctor --cookies ./facebook-cookies.json
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Export birthdays to an ICS calendar:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
fb2cal export --cookies ./facebook-cookies.json \
|
|
102
|
+
--format ics --output ./out/birthdays.ics
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The `out/` directory is ignored by Git when working from a checkout. Keep generated files private
|
|
106
|
+
because they contain personal contact data.
|
|
107
|
+
|
|
108
|
+
### Export formats
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
fb2cal export --cookies ./facebook-cookies.json --format ics --output ./out/birthdays.ics
|
|
112
|
+
fb2cal export --cookies ./facebook-cookies.json --format json --output ./out/birthdays.json
|
|
113
|
+
fb2cal export --cookies ./facebook-cookies.json --format vcf --output ./out/birthdays.vcf
|
|
114
|
+
fb2cal export --cookies ./facebook-cookies.json --format vcf \
|
|
115
|
+
--vcard-version 3.0 --output ./out/birthdays-v3.vcf
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Without `--output`, the selected format is written to stdout. The extraction summary is always
|
|
119
|
+
written to stderr, so exported JSON, VCF, and ICS remain machine-readable:
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
Extraction summary:
|
|
123
|
+
friends with visible birthdays: 621
|
|
124
|
+
birthdays with year: 493
|
|
125
|
+
birthdays without year: 128
|
|
126
|
+
total profile friends: unavailable from the birthday query
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The JSON export contains the same counts under its top-level `summary` object.
|
|
130
|
+
|
|
131
|
+
The VCF export uses vCard 4.0 by default. Dates use the standards-defined basic format, including
|
|
132
|
+
`--MMDD` when Facebook exposes a birthday without a year. Use `--vcard-version 3.0` only for
|
|
133
|
+
address-book clients that do not support vCard 4.0; that legacy format keeps the older hyphenated
|
|
134
|
+
date representation and may be less interoperable for yearless birthdays.
|
|
135
|
+
|
|
136
|
+
## Exporting Chrome cookies safely
|
|
137
|
+
|
|
138
|
+
Treat the exported file as a password: cookies are bearer credentials.
|
|
139
|
+
|
|
140
|
+
1. Open `https://www.facebook.com/events/birthdays/` in Chrome and confirm that the page works.
|
|
141
|
+
2. Use a trusted cookie-export tool to export the complete `facebook.com` cookie jar as JSON. On
|
|
142
|
+
Chrome, [Cookie-Editor](https://chromewebstore.google.com/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm)
|
|
143
|
+
can export the current site's cookies. Remove the extension when finished. A JavaScript snippet
|
|
144
|
+
cannot export `HttpOnly` cookies.
|
|
145
|
+
3. Save the file outside Git, restrict it with `chmod 600 facebook-cookies.json`, and never paste
|
|
146
|
+
its contents into chat, issues, logs, or screenshots. The file must include `c_user` and all
|
|
147
|
+
other Facebook session cookies.
|
|
148
|
+
4. Validate the session without writing an export:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
fb2cal doctor --cookies ./facebook-cookies.json
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
5. If the session expires, authenticate in Chrome again and export a fresh file.
|
|
155
|
+
|
|
156
|
+
## Command reference
|
|
157
|
+
|
|
158
|
+
```text
|
|
159
|
+
fb2cal doctor --cookies PATH [--json] [--log-level LEVEL]
|
|
160
|
+
fb2cal export --cookies PATH [--format ics|json|vcf] [--vcard-version 4.0|3.0] [--output PATH] [--log-level LEVEL]
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`--log-level` accepts `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`. The browser session is
|
|
164
|
+
always supplied explicitly; email/password login and automatic browser-cookie discovery are not
|
|
165
|
+
part of this fork.
|
|
166
|
+
|
|
167
|
+
## Scheduling
|
|
168
|
+
|
|
169
|
+
Run the export once every 24 hours with the scheduler available on your operating system. This
|
|
170
|
+
keeps the calendar current when friends are added or removed and respects later birthday privacy
|
|
171
|
+
changes. The generated ICS file advertises a twelve-hour publication TTL.
|
|
172
|
+
|
|
173
|
+
## Development
|
|
174
|
+
|
|
175
|
+
For source development, use a checkout instead of the installed Release artifact:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
git clone https://github.com/alsd4git/fb2cal.git
|
|
179
|
+
cd fb2cal
|
|
180
|
+
uv sync --locked --dev
|
|
181
|
+
uv run fb2cal --help
|
|
182
|
+
uv run pytest -q
|
|
183
|
+
uv run python -m unittest discover tests
|
|
184
|
+
uv run ruff format --check fb2cal tests --exclude tests/mocks
|
|
185
|
+
uv run ruff check fb2cal tests
|
|
186
|
+
uv build
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
The test suite is fully offline and contains no Facebook credentials or personal data.
|
|
190
|
+
|
|
191
|
+
## Packaging and releases
|
|
192
|
+
|
|
193
|
+
This fork ships wheel and source distributions through tagged GitHub Releases. New builds use the
|
|
194
|
+
distribution name `fb2cal-fork`; the command and Python module are still `fb2cal`. The `fb2cal`
|
|
195
|
+
distribution on PyPI belongs to upstream. Use separate environments if you need both variants
|
|
196
|
+
because they install the same command and module.
|
|
197
|
+
|
|
198
|
+
For versions listed on [PyPI](https://pypi.org/project/fb2cal-fork/#history), run
|
|
199
|
+
`uvx --from fb2cal-fork fb2cal --help` or install with `uv tool install fb2cal-fork`.
|
|
200
|
+
|
|
201
|
+
CI runs tests on Linux, macOS, and Windows with Python 3.11–3.15, plus Python
|
|
202
|
+
3.10 on Linux. On Linux, CI builds the distributions on Python 3.15 and tests
|
|
203
|
+
installing and running each one with Python 3.10 and 3.15. To prepare a new release,
|
|
204
|
+
record user-visible changes in the [changelog](https://github.com/alsd4git/fb2cal/blob/main/CHANGELOG.md),
|
|
205
|
+
update the project version, verify the build,
|
|
206
|
+
and push a matching tag:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
uv sync --locked --dev
|
|
210
|
+
uv build
|
|
211
|
+
git tag -a vX.Y.Z -m "Release vX.Y.Z"
|
|
212
|
+
git push origin vX.Y.Z
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The tag workflow creates a GitHub Release with wheel and sdist artifacts. It does not publish to
|
|
216
|
+
PyPI. Maintainers can run the separate **Publish to PyPI** workflow manually from `main` after
|
|
217
|
+
verifying both assets on the matching stable GitHub Release. It uploads those same files rather
|
|
218
|
+
than rebuilding them.
|
|
219
|
+
|
|
220
|
+
For the first PyPI publication, configure a
|
|
221
|
+
[pending Trusted Publisher](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/)
|
|
222
|
+
for project `fb2cal-fork`, owner `alsd4git`, repository `fb2cal`, workflow `publish-pypi.yml`,
|
|
223
|
+
and GitHub environment `pypi`. Restrict that environment to `main` and complete the publication
|
|
224
|
+
only after maintainer approval. No PyPI API token is needed.
|
|
225
|
+
|
|
226
|
+
## Upstream and contributions
|
|
227
|
+
|
|
228
|
+
- Fork repository: [alsd4git/fb2cal](https://github.com/alsd4git/fb2cal)
|
|
229
|
+
- Fork issues: [alsd4git/fb2cal/issues](https://github.com/alsd4git/fb2cal/issues)
|
|
230
|
+
- Original project: [mobeigi/fb2cal](https://github.com/mobeigi/fb2cal)
|
|
231
|
+
- Open issues in the original project: [mobeigi/fb2cal/issues](https://github.com/mobeigi/fb2cal/issues)
|
|
232
|
+
|
|
233
|
+
Report fork-specific bugs and feature requests in this repository's issue tracker. Fork-specific
|
|
234
|
+
pull requests are welcome here; small changes compatible with the upstream architecture may later
|
|
235
|
+
be proposed upstream as focused pull requests. Report vulnerabilities privately as described in
|
|
236
|
+
[SECURITY.md](https://github.com/alsd4git/fb2cal/blob/main/SECURITY.md).
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
GNU General Public License v3.0 or later. See [LICENSE](https://github.com/alsd4git/fb2cal/blob/main/LICENSE).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
fb2cal/__init__.py,sha256=sKpiFgq_0Kvch9_JYbij41nLBTWNsdsgZRzcwOHVgME,859
|
|
2
|
+
fb2cal/__main__.py,sha256=_9U2q0Q80SiwTM6Abk8kyACn_tCNRSZNYxSZGd3HYcg,5647
|
|
3
|
+
fb2cal/__meta__.py,sha256=FDmI2fgBCNBrgkxGZor6NH0UIQAP4OJiM3KWb_SSExU,1215
|
|
4
|
+
fb2cal/contact.py,sha256=8bQYLubbKNo_L1iyYbynxLi93XofzEjjsbqNFVhlgpQ,1345
|
|
5
|
+
fb2cal/errors.py,sha256=49GRFpG2veX_Dlugx0Kil2vCI9S1m8ya6PN7_NxwUh8,1143
|
|
6
|
+
fb2cal/facebook_client.py,sha256=B4kECsBm9gMnNMQFkPS1ldEOzWj8zJCr3vYyh_H6ji8,3303
|
|
7
|
+
fb2cal/facebook_queries.py,sha256=jAhrTaUH6umiJkgWeQBn9ujPoPUjh_lXsdN4iX7UAE8,2240
|
|
8
|
+
fb2cal/facebook_session.py,sha256=5V49rzFGN5HVXYaeh-EWEz66uBVvBglBi5Gb1ZSawq8,3673
|
|
9
|
+
fb2cal/facebook_token.py,sha256=GpU9MehYOdOOmUKZWqRq5xRTX9CGVeAi-2kq9l-11Uc,1058
|
|
10
|
+
fb2cal/ics_writer.py,sha256=FZ4Kkrw5SlZY_yqE-Whhw_zUy4DehJ-z9WWnDxWedXA,3853
|
|
11
|
+
fb2cal/json_exporter.py,sha256=CCEbAWrXvZ3Q25xw_4ZK0WZODk7L1JPU6_loUSpd5vE,1194
|
|
12
|
+
fb2cal/logger.py,sha256=JUrjCwDG_dGz_Y2C67GY--d8GltltkXn9U67rrB2UCA,823
|
|
13
|
+
fb2cal/pipeline.py,sha256=GYy4VE5rgpVC9pGQx_-kvlGHmqZCjV7dbNeuCYhuUps,1460
|
|
14
|
+
fb2cal/text_format.py,sha256=sGdgOzPZXosA4UMvtYsTjVTRd7-p2VPN02qe7n1KFyU,1026
|
|
15
|
+
fb2cal/transformer.py,sha256=gzWVZi59KZN9EOK9TqdfictLBEONI-kFfnZZidG7RQs,1801
|
|
16
|
+
fb2cal/utils.py,sha256=Jqc8_u2UPFgIBnVpHRnFSdRSSLhLHbmxRzlSa6-L5NM,490
|
|
17
|
+
fb2cal/vcard_exporter.py,sha256=SxL-Z19alZfTYXloGJMY8dGXzSbFp4AcidnfI-gRd30,3026
|
|
18
|
+
fb2cal_fork-2.0.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
19
|
+
fb2cal_fork-2.0.1.dist-info/METADATA,sha256=7AozIn-Te-etrYGsN_NDRr1eIabgDlJzmzAbxR5N3B0,10133
|
|
20
|
+
fb2cal_fork-2.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
21
|
+
fb2cal_fork-2.0.1.dist-info/entry_points.txt,sha256=PQjpeiAmzjifMFRWKQPoy1WS1QrfKpaBkxBKz3TJ5e0,48
|
|
22
|
+
fb2cal_fork-2.0.1.dist-info/top_level.txt,sha256=EatIRuF1a6_CCBYufR2GKS66aABUSanf6CyQIJEml1w,7
|
|
23
|
+
fb2cal_fork-2.0.1.dist-info/RECORD,,
|