Skip to content

Commit

Permalink
Blue sky update (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachosen1 authored Dec 23, 2024
1 parent 4b6faa6 commit 9e52420
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
15 changes: 5 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
UploadEarthQuakeLocation,
get_date_range_summary,
)

from nearquake.post_manager import post_to_all_platforms, save_tweet_to_db
from nearquake.post_manager import post_and_save_tweet
from nearquake.open_ai_client import generate_response
from nearquake.utils import convert_datetime, format_earthquake_alert
from nearquake.utils.db_sessions import DbSessionManager
Expand Down Expand Up @@ -100,8 +99,7 @@
post_type="fact",
message=message,
)
post_to_all_platforms(tweet_text=tweet_text.get("post"))
save_tweet_to_db(tweet_text, conn)
post_and_save_tweet(tweet_text, conn)

if args.weekly:
run.upload(url=generate_time_period_url("week"))
Expand All @@ -125,8 +123,7 @@
post_type="fact",
message=message,
)
post_to_all_platforms(tweet_text=tweet_text.get("post"))
save_tweet_to_db(tweet_text, conn)
post_and_save_tweet(tweet_text, conn)

if args.monthly:
run.upload(url=generate_time_period_url("month"))
Expand All @@ -150,8 +147,7 @@
post_type="fact",
message=message,
)
post_to_all_platforms(tweet_text=tweet_text.get("post"))
save_tweet_to_db(tweet_text, conn)
post_and_save_tweet(tweet_text, conn)

if args.initialize:
create_database(url=POSTGRES_CONNECTION_URL, schema=["earthquake", "tweet"])
Expand All @@ -162,8 +158,7 @@

tweet_text = format_earthquake_alert(post_type="fact", message=message)

post_to_all_platforms(tweet_text=tweet_text.get("post"))
save_tweet_to_db(tweet_text, conn)
post_and_save_tweet(tweet_text, conn)

if args.backfill:
start_date = input("Type Start Date:")
Expand Down
4 changes: 2 additions & 2 deletions nearquake/data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
generate_coordinate_lookup_detail_url,
generate_time_range_url,
)
from nearquake.post_manager import post_to_all_platforms
from nearquake.post_manager import post_and_save_tweet
from nearquake.utils import (
convert_timestamp_to_utc,
fetch_json_data_from_url,
Expand Down Expand Up @@ -319,7 +319,7 @@ def upload(self):
)

try:
post_to_all_platforms(post_text=tweet_text)
post_and_save_tweet(tweet_text, self.conn)

except Exception as e:
_logger.error(
Expand Down
21 changes: 17 additions & 4 deletions nearquake/post_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,20 @@ def save_tweet_to_db(tweet_text: dict, conn) -> bool:
return False


def post_to_all_platforms(post_text: str) -> dict:
platforms = [TwitterPost(), BlueSkyPost()]
for platform in platforms:
platform.post(post_text)
_PLATFORM = [TwitterPost(), BlueSkyPost()]


def post_to_all_platforms(text: str) -> dict:
for platform in _PLATFORM:
platform.post(text)


def post_and_save_tweet(text: dict, conn) -> None:
"""
Post tweet to all platforms and save to database
:param tweet_text: Tweet content
:param conn: Database connection
"""
post_to_all_platforms(text=text.get("post"))
save_tweet_to_db(text, conn)

0 comments on commit 9e52420

Please sign in to comment.