# -*- coding: utf-8 -*-
"""
Created on Mon Jul 26 13:39:21 2021

@author: Mark B
"""

import requests
import numpy as np

url = r"https://www.drroyspencer.com/2022/04/uah-global-temperature-update-for-march-2022-0-15-deg-c/#comments"

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}

response = requests.get(url, verify=False, headers=headers)

countDict = {}
totalPosts = 0

for line in response.text.splitlines():
   if '<span class="says">says:' in line:
       totalPosts += 1
       name = line.split(">")[1].split("<")[0]
       if name == "":
           name = line.split(">")[2].split("<")[0]
       if name in countDict:
           countDict[name] += 1
       else:
           countDict[name] = 1
           
names = list(countDict.keys())
counts = [countDict[name] for name in names]
countIndex = np.argsort(counts)

print("Total Posts: {0:d}".format(totalPosts))
for index in reversed(countIndex):
    print("{0:s} : {1:d}".format(names[index], countDict[names[index]]))