Skip to content

Commit

Permalink
feat: update instagram data source to get media instead of biography (#…
Browse files Browse the repository at this point in the history
…122)

<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰    
v    Before smashing the submit button please review the checkboxes.
v If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

## Description
<!-- Small description -->

This PR updates the Instagram data source to get media instead of
biography.

Depends-On: #117 

## Checklist
- [ ] Targeted PR against correct branch.
- [ ] Linked to Github issue with discussion and accepted design OR link
to spec that describes this work.
- [ ] Wrote unit tests.
- [ ] Updated the documentation. 
- [ ] Re-reviewed `Files changed` in the Github PR explorer.
  • Loading branch information
dadamu committed Aug 14, 2023
1 parent 90a6aef commit 103aa89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions data-sources/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def __init__(self, address: str, pub_key: str, value: str, signature: str):
self.value = value


def get_urls_from_biography(user: str) -> [str]:
def get_urls_from_caption(user: str) -> [str]:
"""
Returns all the URLs that are found inside the biography of the user having the given user username.
Returns all the URLs that are found inside the caption of the user having the given user username.
:param user: Username of the Instagram user.
:return: List of URLs that are found inside the biography
:return: List of URLs that are found inside the caption
"""
url = f"{ENDPOINT}/users/{user}"
url = f"{ENDPOINT}/medias/{user}"
result = requests.request("GET", url, headers=HEADERS).json()
return re.findall(r'(https?://[^\s]+)', result['biography'])
return re.findall(r'(https?://[^\s]+)', result['caption'])


def get_signature_from_url(url: str) -> Optional[VerificationData]:
Expand Down Expand Up @@ -144,7 +144,7 @@ def main(args: str):
:param args: JSON encoded parameters used during the execution.
:return The signed value and the signature as a single comma separated string.
:raise Exception if anything is wrong during the process. This can happen if:
1. The Instagram user has not started the connection using the Hephaestus bot
1. The Instagram user has not started the connection
2. The provided signature is not valid
3. The provided address is not linked to the provided public key
"""
Expand All @@ -153,10 +153,10 @@ def main(args: str):
json_obj = json.loads(decoded)
call_data = check_values(json_obj)

# Get the URLs to check from the user biography
urls = get_urls_from_biography(call_data.username)
# Get the URLs to check from the caption of the user media
urls = get_urls_from_caption(call_data.username)
if len(urls) == 0:
raise Exception(f"No URL found inside {call_data.username} biography")
raise Exception(f"No URL found inside {call_data.username} media")

# Find the signature following the URLs
data = None
Expand All @@ -167,7 +167,7 @@ def main(args: str):
break

if data is None:
raise Exception(f"No valid signature data found inside {call_data.username} biography")
raise Exception(f"No valid signature data found inside {call_data.username} media")

# Verify the signature
signature_valid = verify_signature(data)
Expand Down
8 changes: 4 additions & 4 deletions data-sources/instagram_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
class TestInstagram(unittest.TestCase):

@httpretty.activate(verbose=True, allow_net_connect=False)
def test_get_urls_from_biography(self):
def test_get_urls_from_caption(self):
# Register fake HTTP call
httpretty.register_uri(
httpretty.GET,
"https://themis.mainnet.desmos.network/instagram/users/riccardomontagnin",
"https://themis.mainnet.desmos.network/instagram/medias/riccardomontagnin",
status=200,
body='{"biography":"https://pastebin.com/raw/TgSpUCz6"}',
body='{"caption":"https://pastebin.com/raw/TgSpUCz6"}',
)

url = instagram.get_urls_from_biography('riccardomontagnin')
url = instagram.get_urls_from_caption('riccardomontagnin')
self.assertEqual(['https://pastebin.com/raw/TgSpUCz6'], url)

@httpretty.activate(verbose=True, allow_net_connect=False)
Expand Down

0 comments on commit 103aa89

Please sign in to comment.