Skip to content

Commit

Permalink
Merge pull request #19 from tblanarik/tblanarik/url-formatting
Browse files Browse the repository at this point in the history
Moving and formatting
  • Loading branch information
tblanarik authored Sep 28, 2024
2 parents 5aa7e55 + df08b89 commit e037b74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions spotbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def run(req):
req_body = req.get_json()
logging.info(f"Received JSON: {req_body}")

content = create_content(req_body)
callsign = req_body.get('callsign')

table = tables.get_table()
entity = tables.query_for_entity(table, callsign)
messageId = None
if is_entity_recent(entity):
messageId = entity['MessageId']
content = create_content(req_body)
messageId = call_target(content, messageId)
tables.upsert_entity(table, callsign, messageId)

Expand All @@ -33,15 +33,15 @@ def create_content(req_body):
spot_deeplink = create_spot_deeplink(source, callsign, wwffRef)

# flags = 4 means it will suppress embeds: https://discord.com/developers/docs/resources/message#message-object-message-flags
content = {"content": f"{callsign} | {source} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef} | {spot_deeplink}", "flags": 4}
content = {"content": f"{callsign} | {spot_deeplink} | freq: {frequency} | mode: {mode} | loc: {summitRef}{wwffRef}", "flags": 4}
return content

def create_spot_deeplink(source, callsign, wwffRef):
match source:
case "sotawatch":
return f"[See their latest spot](https://sotl.as/activators/{callsign})"
return f"[{source}](https://sotl.as/activators/{callsign})"
case "pota":
return f"[See their latest spot](https://api.pota.app/spot/comments/{callsign}/{wwffRef})"
return f"[{source}](https://api.pota.app/spot/comments/{callsign}/{wwffRef})"
case _:
return ""

Expand Down
4 changes: 2 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class TestSpotBot(unittest.TestCase):
def test_function_app_basic(self):
req_body = {"callsign":"KI7HSG", "source": "pota", "frequency": "14.074", "mode": "FT8", "wwffRef":"US-0052"}
content = spotbot.create_content(req_body)
expected = {'content': 'KI7HSG | pota | freq: 14.074 | mode: FT8 | loc: US-0052 | [See their latest spot](https://api.pota.app/spot/comments/KI7HSG/US-0052)', 'flags': 4}
expected = {'content': 'KI7HSG | [pota](https://api.pota.app/spot/comments/KI7HSG/US-0052) | freq: 14.074 | mode: FT8 | loc: US-0052', 'flags': 4}
self.assertDictEqual(content, expected)

def test_function_app(self):
req_body = {"callsign":"KI7HSG", "source": "sotawatch", "frequency": "14.074", "mode": "FT8", "summitRef": "ABCD"}
content = spotbot.create_content(req_body)
expected = {'content': 'KI7HSG | sotawatch | freq: 14.074 | mode: FT8 | loc: ABCD | [See their latest spot](https://sotl.as/activators/KI7HSG)', 'flags': 4}
expected = {'content': 'KI7HSG | [sotawatch](https://sotl.as/activators/KI7HSG) | freq: 14.074 | mode: FT8 | loc: ABCD', 'flags': 4}
self.assertDictEqual(content, expected)

if __name__ == '__main__':
Expand Down

0 comments on commit e037b74

Please sign in to comment.