Browse Source

Initial commit.

opi 8 years ago
commit
10d8390c25
2 changed files with 56 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 54 0
      isp2csv.py

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+*.json
+*.csv

+ 54 - 0
isp2csv.py

@@ -0,0 +1,54 @@
+import csv
+import json 
+import requests 
+
+# CSV output
+csv_output = csv.writer(open("isp.csv", "wb+"))
+csv_output.writerow([
+    "Name",
+    "Short name",
+    "Website",
+    "email",
+    "Creation date",
+    "Covered areas",
+    "Members count",
+    "Subscribers count",
+    "FFDN member since",
+    "Logo url"
+])
+
+# API endpoint
+url = 'https://db.ffdn.org/api/v1/isp/'
+params = dict(
+    per_page=100
+)
+
+# Call API
+resp = requests.get(url=url, params=params)
+data = json.loads(resp.text)
+
+# Loop through ISPs
+for isp in data["isps"]:
+    if isp["is_ffdn_member"]:
+
+        # Mix coveredAreas as a string
+        coveredAreas = []
+        for area in isp["ispformat"]["coveredAreas"]:
+            coveredAreas.append('{areas} ({tech})'.format(
+                areas=area["name"].encode('UTF-8','ignore'),
+                tech=", ".join(area["technologies"]).encode('UTF-8','ignore')
+            ))
+
+        # ISP row
+        csv_output.writerow([
+            isp["ispformat"]["name"].encode('UTF-8','ignore'),
+            isp["ispformat"]["shortname"].encode('UTF-8','ignore') if 'shortname' in isp["ispformat"] else "",
+            isp["ispformat"]["email"].encode('UTF-8','ignore') if 'email' in isp["ispformat"] else "",
+            isp["ispformat"]["creationDate"].encode('UTF-8','ignore') if 'creationDate' in isp["ispformat"] else "",
+            isp["ispformat"]["website"].encode('UTF-8','ignore') if 'website' in isp["ispformat"] else "",
+            " ".join(coveredAreas),
+            isp["ispformat"]["memberCount"] if 'memberCount' in isp["ispformat"] else "",
+            isp["ispformat"]["subscriberCount"] if 'subscriberCount' in isp["ispformat"] else "",
+            isp["ispformat"]["ffdnMemberSince"].encode('UTF-8','ignore') if 'ffdnMemberSince' in isp["ispformat"] else "",
+            isp["ispformat"]["logoURL"].encode('UTF-8','ignore') if 'logoURL' in isp["ispformat"] else "",
+        ])