Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Last active January 20, 2023 10:11
Show Gist options
  • Save random-robbie/097c32c7bd2c15a62a87b46dc571eef2 to your computer and use it in GitHub Desktop.
Save random-robbie/097c32c7bd2c15a62a87b46dc571eef2 to your computer and use it in GitHub Desktop.
add domains from csv to uptime robot
import requests
import csv
import time
apiKey = "KEY"
def add_monitor (apiKey,domain,friendly):
url = "https://api.uptimerobot.com/v2/newMonitor"
payload = "api_key="+apiKey+"&format=xml&type=1&url=https://www."+domain+"&sub_type=2&friendly_name="+friendly+""
headers = {
'cache-control': "no-cache",
'content-type': "application/x-www-form-urlencoded"
}
response = requests.request("POST", url, data=payload, headers=headers)
rr = response.text
return rr
def make_friendly (domain):
new = domain.replace("https://","")
new = new.replace(".co.uk","")
new = new.replace (".com","")
new = new.replace (".org","")
new = new.replace (".gb.net","")
new = new.replace (".net","")
new = new.replace (".biz","")
new = new.replace("www.","")
return new
with open('fetchcsv.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
domain = str(row[0])
friendly = make_friendly (str(row[0]))
print ("[*]Adding "+domain+" to uptimerobot as friendly name "+friendly+"[*]\n")
adding = add_monitor (apiKey,domain,friendly)
if 'status="1"' not in adding:
print ("[*]Adding Monitor has failed for "+domain+"[*]")
print adding
time.sleep (60000)
else:
print ("[*]"+domain+" has been added successfully [*]")
#print adding
@tomscholz
Copy link

What should the CSV look like?

@georgetasioulis
Copy link

Indeed, that would be interesting to know. How should the CSV be structured? Can you provide a sample?

@mortenbirkelund
Copy link

Just make a csv file called fetchcsv.csv that contains one url on each line. Works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment