xxxxxxxxxx
import requests
import time
import random
from datetime import datetime, timedelta
def get_seconds_until_next_minute():
current_time = datetime.now()
next_minute = current_time + timedelta(minutes=1)
next_minute = next_minute.replace(second=0, microsecond=0)
remaining_seconds = (next_minute - current_time).total_seconds()
return remaining_seconds
def multi_api(stock_name, date, data_type='high'):
api_keys = [
"6ppmZm9JKpqPLb5JHgNsENMZC6E6ORod",
"cDT6Z0uRbv3KS2ipbYRVhGdhflKHz3f9",
"pQ_3uhxDaH5KNpyZWYV60swl4vCom7Fa",
"ErxKKvFge8coIlOzlmHHe3IgIvU3BRdk",
]
base_url = "https://api.polygon.io/v1/open-close/{}/{}/?adjusted=true&apiKey={}"
while True:
# Randomly shuffle the API keys for the first attempt
random.shuffle(api_keys)
for api_key in api_keys:
url = base_url.format(stock_name, date, api_key)
try:
response = requests.get(url)
parsed_data = response.json()
data_value = parsed_data.get(data_type)
print(f"API request successful. {data_type} value:", data_value)
time.sleep(1) # Add a 1-second delay
return data_value
except Exception as e:
print(f"Failed to make API request for {url}. Error: {e}")
print("All API requests failed. Waiting until the next minute...")
remaining_seconds = get_seconds_until_next_minute()
time.sleep(remaining_seconds)
# Example usage:
stock_name = "MSFT"
date = "2023-12-10"
data_type = "low" # Change to the desired data type
result = multi_api(stock_name, date, data_type)
xxxxxxxxxx
Y
.-^-.
/ \ .- ~ ~ -.
() () / _ _ `. _ _ _
\_ _/ / / \ \ . ~ _ _ ~ .
| | / / \ \ .' .~ ~-. `.
| | / / ) ) / / `.`.
\ \_ _/ / / / / / `'
\_ _ _.' / / ( (
/ / \ \
/ / \ \
/ / ) )
( ( / /
`. `. .' /
`. ~ - - - - ~ .'
~ . _ _ _ _ . ~
xxxxxxxxxx
Python is an interpreted, high-level,
general-purpose programming language.
//as you can also see to your right --------------------->
but also note interpreted, not compiled.
xxxxxxxxxx
Python is a High level and multi-purpose Programming language. It is commonly
used in data science ,AI(Artificial intelligence) and ML(Machine Learning).
If you are a beginner in programming it is mostly prefered because its
code is very simple and somehow similar to English Language.Even master level
people use python. Encourage you to learn it.
xxxxxxxxxx
Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
xxxxxxxxxx
'''Python is an interpreted, high-level and general-purpose programming
language.Python's design philosophy emphasizes code readability with its
notable use of significant whitespace. '''
#Examples
print("Hello World")
repeat = 5
for i in range(repeat):
print("This is the %i iteration" % i)
#2nd variation - print("This is the " + i + "iteration")
#3rd variation - print(f"This is the {i!r} iteration")
#4th variation - print(("This is the {} iteration).format(i))
import random #In order to use the random functions
class Person:
def __init__(self, name, age, height):
self.name = str(name)
self.age = int(age)
self.height = str(height)
person1 = Person("Name", random.randint(1, 100), str(random.randint(0, 7)) + "'" + str(random.randint(0, 11)) + '"')
print(f"Your name is {person1.name} and you are {person1.age} years old. You are also {person1.height}.")