fPaste.me

A free, anonymous, minimalist and open source paste tool.


Untitled
04-10-2019 16:25:22
Anonymous
import json, codecs
from urllib import parse
i = 0
url = []
count = 0
previous_domain = ""

with open('/home/ivan/Загрузки/1.json') as f:
templates = json.load(f)

for section in templates:
url.append(section['url'])
url = sorted(url)
for i in url:
domain = parse.urlsplit(i).netloc
if domain != "":
if previous_domain == domain:
count += 1
elif previous_domain == '':
count = 1
previous_domain = domain
else:
data = 'url:'+previous_domain + ',' 'count:'+ str(count)
count = 1
previous_domain = domain
with codecs.open('/home/ivan/Загрузки/2.json', 'a', 'utf8') as f:
f.write(json.dumps(data, sort_keys=True, ensure_ascii=True, separators=(',',';')))

else:
domain = i
if previous_domain == domain:
count += 1
elif previous_domain == '':
count = 1
previous_domain = domain
else:
data = 'url:'+previous_domain + ',' 'count:'+ str(count)
count = 1
previous_domain = domain
with codecs.open('/home/ivan/Загрузки/2.json', 'a', 'utf8') as f:
f.write(json.dumps(data, sort_keys=True, ensure_ascii=True, separators=(',',' ')))