-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30b3c91
commit 16afae9
Showing
1 changed file
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |