-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (26 loc) · 1.17 KB
/
main.py
File metadata and controls
37 lines (26 loc) · 1.17 KB
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
34
35
36
37
import csv
import time
import requests
from dotenv import load_dotenv # Remove if API key is not required
from os import environ # Remove if API key is not required
load_dotenv() # Remove if API key is not required
API_LINK = "https://example.com/api?key={}&api_key={}" # Remove the api_key parameter if API key is not required
API_KEY = environ.get("API_KEY") # Remove if API key is not required
TIME_TO_WAIT = 1 # Time to wait between API calls in seconds (set to 0 for no wait)
FILE_PATH = "resources/temp.csv" # Path to the CSV file
def main():
process_csv(FILE_PATH)
def process_csv(file_path):
with open(file_path, mode='r', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
for item in row:
if item == "":
continue
url = API_LINK.format(item, API_KEY) # Remove the API_KEY parameter if API key is not required
response = requests.get(url)
print(f"Response for {item}: {response.status_code} - {response.text}\n")
if TIME_TO_WAIT != 0:
time.sleep(TIME_TO_WAIT)
if __name__ == "__main__":
main()