-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
33 lines (28 loc) · 878 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import boto3
from settings import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION
def get_page(url, headers=None):
"""
Get the page HTML content
:param headers: the headers dictionary to add to the request object
:param url: the url to extract the contents
:return: Request content of the given url
"""
if headers:
result = requests.get(url, headers=headers)
else:
result = requests.get(url)
if result.status_code != 200:
result.raise_for_status()
else:
return result.content
def get_db():
"""
Start a dynamodb session with boto3
:return: boto3's Session object
"""
return boto3.Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name=AWS_DEFAULT_REGION
).resource("dynamodb")