Skip to content

Commit

Permalink
added util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Chen1 committed Feb 16, 2024
1 parent 30b3c91 commit 16afae9
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion swan/common/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
# ./swan/common/utils.py
import requests

def parse_params_to_str(params):
url = '?'
for key, value in params.items():
url = url + str(key) + '=' + str(value) + '&'
return url[0:-1]
return url[0:-1]

def list_repo_contents(user, repo):
"""
Lists the contents of a GitHub repository.
Parameters:
user (str): The username of the repository owner.
repo (str): The name of the repository.
Returns:
list: A list of dictionaries representing the files in the repository.
"""
url = f'https://api.github.com/repos/{user}/{repo}/contents'
response = requests.get(url)
response.raise_for_status()
return response.json()

def read_file_from_url(url):
"""
Reads a file from a URL.
Parameters:
url (str): The URL of the file.
Returns:
str: The content of the file.
"""
response = requests.get(url)
response.raise_for_status()
return response.text

0 comments on commit 16afae9

Please sign in to comment.