Compare commits
3 Commits
aa92b77150
...
9cf12b1bdd
Author | SHA1 | Date | |
---|---|---|---|
9cf12b1bdd | |||
981cb12aa6 | |||
0a5c80e87c |
@ -1,50 +1,84 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pyclip
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
from .MembershipWorks import MembershipWorks
|
|
||||||
|
|
||||||
|
|
||||||
def format_event(membershipworks: MembershipWorks, event):
|
def format_event(event_details, truncate: bool):
|
||||||
event_details = membershipworks.get_event_by_eid(event["eid"])
|
|
||||||
url = (
|
url = (
|
||||||
"https://claremontmakerspace.org/events/#!event/register/"
|
"https://claremontmakerspace.org/events/#!event/register/"
|
||||||
+ event_details["url"]
|
+ event_details["url"]
|
||||||
)
|
)
|
||||||
if "lgo" in event_details:
|
if "lgo" in event_details:
|
||||||
img = f"""<img class="aligncenter" width="500" height="500" src="{event_details['lgo']['l']}">"""
|
img = (
|
||||||
|
f"""<img class="alignleft" width="400" src="{event_details['lgo']['l']}">"""
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
img = ""
|
img = ""
|
||||||
# print(json.dumps(event_details))
|
# print(json.dumps(event_details))
|
||||||
return f"""<h2 style="text-align: center;">
|
out = f"""<h2 style="text-align: center;">
|
||||||
<a href="{url}">
|
<a href="{url}">{img}{event_details['ttl']}</a>
|
||||||
{img}
|
|
||||||
{event_details['ttl']}
|
|
||||||
</a>
|
|
||||||
</h2>
|
</h2>
|
||||||
<div>{event_details['szp']} — {event_details['ezp']}</div>
|
<div><i>{event_details['szp']} — {event_details['ezp']}</i></div>
|
||||||
|
"""
|
||||||
|
if not truncate:
|
||||||
|
out += f"""
|
||||||
<div>
|
<div>
|
||||||
{event_details['dtl']}
|
{event_details['dtl']}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a href="{url}">Register for this class now!</a>"""
|
<a href="{url}">Register for this class now!</a>"""
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def format_section(title: str, blurb: str, events, truncate: bool):
|
||||||
|
# skip empty sections
|
||||||
|
if not events:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
events_list = "\n<hr />\n\n".join(format_event(event, truncate) for event in events)
|
||||||
|
|
||||||
|
return f"""<h1>{title}</h1>
|
||||||
|
<h4><i>{blurb}</i></h4>
|
||||||
|
{events_list}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def generate_post():
|
||||||
config = Config()
|
config = Config()
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
membershipworks = config.membershipworks
|
membershipworks = config.membershipworks
|
||||||
events = membershipworks.get_events_list(datetime.now())
|
events = membershipworks.get_events_list(now)
|
||||||
if "error" in events:
|
if "error" in events:
|
||||||
print("Error:", events["error"])
|
print("Error:", events["error"])
|
||||||
return
|
return
|
||||||
|
|
||||||
events_list = "\n<hr />\n\n".join(
|
ongoing_events = []
|
||||||
format_event(membershipworks, event)
|
full_events = []
|
||||||
for event in events["evt"]
|
upcoming_events = []
|
||||||
if event["cal"] != 0 # ignore hidden events
|
for event in events["evt"]:
|
||||||
)
|
# ignore hidden events
|
||||||
|
if event["cal"] == 0:
|
||||||
|
continue
|
||||||
|
event_details = membershipworks.get_event_by_eid(event["eid"])
|
||||||
|
|
||||||
|
# registration has already ended
|
||||||
|
if (
|
||||||
|
"erd" in event_details
|
||||||
|
and datetime.fromtimestamp(event_details["erd"]) < now
|
||||||
|
):
|
||||||
|
ongoing_events.append(event_details)
|
||||||
|
# class is full
|
||||||
|
elif event_details["cnt"] >= event_details["cap"]:
|
||||||
|
full_events.append(event_details)
|
||||||
|
else:
|
||||||
|
upcoming_events.append(event_details)
|
||||||
|
|
||||||
header = """<p><img class="aligncenter size-medium wp-image-2319" src="https://claremontmakerspace.org/wp-content/uploads/2019/03/CMS-Logo-b-y-g-300x168.png" alt="" width="300" height="168" /></a></p>
|
header = """<p><img class="aligncenter size-medium wp-image-2319" src="https://claremontmakerspace.org/wp-content/uploads/2019/03/CMS-Logo-b-y-g-300x168.png" alt="" width="300" height="168" /></a></p>
|
||||||
<p>Greetings Upper Valley Makers:</p>
|
<p>Greetings Upper Valley Makers:</p>
|
||||||
<p>We have an exciting list of upcoming classes at the Claremont MakerSpace that we think might interest you.</p>
|
<p>We have an exciting list of upcoming classes at the Claremont MakerSpace that we think might interest you.</p>
|
||||||
@ -59,7 +93,7 @@ def main():
|
|||||||
<hr />
|
<hr />
|
||||||
"""
|
"""
|
||||||
|
|
||||||
footer = """
|
footer = """<div style="clear: both;">
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
<div>Happy Makin’!</div>
|
<div>Happy Makin’!</div>
|
||||||
@ -67,7 +101,36 @@ def main():
|
|||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print(header, events_list, footer)
|
yield header
|
||||||
|
yield format_section(
|
||||||
|
"Upcoming Events",
|
||||||
|
"Events that are currently open for registration.",
|
||||||
|
upcoming_events,
|
||||||
|
truncate=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield format_section(
|
||||||
|
"Just Missed",
|
||||||
|
"These classes are currently full at time of writing. If you are interested, please check the event's page; spots occasionally open up. Keep an eye on this newsletter to see when these classes are offered again.",
|
||||||
|
full_events,
|
||||||
|
truncate=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield format_section(
|
||||||
|
"Ongoing",
|
||||||
|
"These classes are ongoing. Registration is closed, but they may be offered again in the future.",
|
||||||
|
ongoing_events,
|
||||||
|
truncate=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
yield (footer)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
result = "\n".join(generate_post())
|
||||||
|
print(result)
|
||||||
|
pyclip.copy(result)
|
||||||
|
print("Copied to clipboard!", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
1517
poetry.lock
generated
1517
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -23,6 +23,7 @@ lxml = "^4.5.0"
|
|||||||
peewee = "^3.13.2"
|
peewee = "^3.13.2"
|
||||||
mysqlclient = "^2.1.0"
|
mysqlclient = "^2.1.0"
|
||||||
udm-rest-client = "^1.0.6"
|
udm-rest-client = "^1.0.6"
|
||||||
|
pyclip = "^0.7.0"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
black = "^22.3.0"
|
black = "^22.3.0"
|
||||||
|
Reference in New Issue
Block a user