#!/usr/bin/python3

import requests
from requests.structures import CaseInsensitiveDict

site = 'http://fam-tille.de/'

# https://stackoverflow.com/questions/55872164/how-to-rotate-proxies-on-a-python-requests/68451842#68451842
from requests_ip_rotator import ApiGateway

#gateway = ApiGateway(site,regions=["eu-west-1", "eu-west-2"])
gateway = ApiGateway(site,regions=["eu-central-1"])
gateway.start()
#print("gateway = ", gateway)
#print(dir(gateway))
print(vars(gateway))
print(gateway.endpoints)


#https://reqbin.com/req/python/gplpbyk6/get-request-like-mozilla-firefox
headers = CaseInsensitiveDict()
headers["Connection"] = "keep-alive"
headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0"
headers["Upgrade-Insecure-Requests"] = "1"
headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"

session = requests.Session()
session.mount(site, gateway)
# print("session = ", session)
print(vars(session))

import pprint

#response = session.get(site+'leblauf.html', headers = headers)
response = session.get(site+'lgi-bin/advent?y=2021&m=12&d=18', headers = headers)
pprint.pprint(vars(response))
pprint.pprint(vars(response.connection))
pprint.pprint(vars(response.raw))
#print(response['url'])
if response.status_code == 404:
    print("Failed to access %s. (status=%i)" % (site,response.status_code) )
    gateway.shutdown() 
    exit(1)
if response.status_code != 200:
    print("Non-default response status code: ", response.status_code)
#print(response.text)
gateway.shutdown() 
