Last active
May 17, 2024 21:49
-
-
Save kamleong/531d80b3de933f86179a49173ddf3245 to your computer and use it in GitHub Desktop.
file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
print(sys.argv[0]) ## __file__ | |
filepath = sys.argv[1] if len(sys.argv) > 1 else r"C:\Windows\win.ini" | |
print(filepath) | |
#f2 = open(r"B:\a.txt","a+") | |
#f2.write("Hello \n") | |
#f2.close() | |
dictObj = {} | |
import re | |
with open(filepath, encoding="utf-8") as f1: | |
count = 0 | |
while True: | |
line = f1.readline() | |
if not line: break | |
count = count + 1 | |
line = line.strip() | |
if line=="": continue | |
print(line) | |
if line.startswith("http") : | |
m = re.search(r'http[s]?://([^\/\:]+)', line) | |
host = m.group(1) | |
#print( host ) | |
if host not in dictObj : dictObj[host] = 0 | |
dictObj[host] = dictObj[host] + 1 | |
# if | |
# while | |
dictObj = dict(sorted(dictObj.items(), key=lambda x:x[1], reverse=True)) | |
#print(dictObj) | |
count = 0 | |
for k in dictObj : | |
count = count + 1 | |
v = dictObj[k] | |
print(k + " [" + str(v) + "]") | |
#if count > 5 : break | |
# for | |
# with | |
quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment