Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions 05_github.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
#!/usr/bin/env python

import json # to parse JSON
import requests # to make HTTP requests
import argparse # to parse command-line arguments
import requests
import time

if __name__ == "__main__":
url_1 = "https://api.github.com/emaadmanzoor"
r = requests.get(url_1)
print(r.status_code)
print(r.json())

url_2 = "https://api.github.com/users/emaadmanzoor"
r = requests.get(url_2)
print(r.status_code)

for key, value in r.json().items():
print(key, value)

print(r.headers)

reset_time = r.headers["x-ratelimit-reset"]
print("Rate limit resets at:", reset_time)

remaining = r.headers["x-ratelimit-remaining"]
print("API calls remaining:", remaining)

current_time = time.time()
reset_time = int(reset_time) # the API gives you a string, not an integer
remaining_time = reset_time - current_time
print("Remaining time (seconds)",
remaining_time)

print("Sleeping until reset...")
time.sleep(remaining_time)
url_1= "https://api.github.com/emaadmanzoor"
rounds = 0

while rounds < 10:
r = requests.get(url_1)
stacode = r.status_code
if stacode == 403:
print("the status code is", r.status_code)
break
else:
rounds = rounds + 1
print ("Tried", rounds, "rounds and the status code is", stacode)

time.sleep(1)
print ("This is an invalid URL which return status code 404 after 10-round trial")
53 changes: 53 additions & 0 deletions challengelab02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import boto3

# Creating the low level functional client
client = boto3.client(
's3',
aws_access_key_id = "AKIAUN6JRXCTE5ZDYPW6",
aws_secret_access_key = "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",
region_name = 'us-west-1'
)

# Creating the high level object oriented interface
resource = boto3.resource(
's3',
aws_access_key_id = "AKIAUN6JRXCTE5ZDYPW6",
aws_secret_access_key = "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",
region_name = 'us-west-1'
)

# Fetch the list of existing buckets
clientResponse = client.list_buckets()

# Print the bucket names one by one
print('Printing bucket names...')
for bucket in clientResponse['Buckets']:
print(f'Bucket Name: {bucket["Name"]}')


# Creating a bucket in AWS S3
location = {'LocationConstraint': 'us-west-1'}
client.create_bucket(
Bucket = 'challengea-lab02-1',
CreateBucketConfiguration=location
)

# Create the S3 object
obj = client.get_object(
Bucket = 'challengea-lab02-2',
Key = 'challengea-lab02-FangshuoLiu.csv'
)

# Read data from the S3 object
data = pandas.read_csv(obj['Body'])

# Print the data frame
print('Printing the data frame...')
print(data)

s3 = boto3.resources("s3")
s3.Bucket("challengea-lab02-1").upload_file("/home/gb760/Lab02/hhh.txt","hhh.txt")