Audio analyzer
This commit is contained in:
28
audio-analyzer.py
Normal file
28
audio-analyzer.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import pymongo
|
||||||
|
|
||||||
|
pazanIds = None
|
||||||
|
|
||||||
|
pazansFileName = sys.argv[1]
|
||||||
|
with open(pazansFileName) as file:
|
||||||
|
pazanIds = json.loads(file.read()).keys()
|
||||||
|
|
||||||
|
artistStats = dict()
|
||||||
|
|
||||||
|
audioCollection = pymongo.MongoClient("goto.reproducible.work")["vk"]["audio"]
|
||||||
|
for pazanId in pazanIds:
|
||||||
|
for audio in audioCollection.find({"owner_id": pazanId}, {"artist": 1, "title": 1, "url": 1}):
|
||||||
|
audioName = audio["artist"] + audio["title"]
|
||||||
|
artistStatsItem = artistStats.get(audioName, {
|
||||||
|
"url": audio["url"],
|
||||||
|
"count": 0
|
||||||
|
})
|
||||||
|
artistStatsItem["count"] += 1
|
||||||
|
artistStats[audioName] = artistStatsItem
|
||||||
|
|
||||||
|
with open(sys.argv[2], "w", encoding="utf-8") as file:
|
||||||
|
for item in sorted(artistStats.items(), key=lambda item: item[1]["count"], reverse=True):
|
||||||
|
file.write(item[0] + "\n")
|
||||||
|
file.write("\tcount: " + str(item[1]["count"]) + "\n")
|
||||||
|
file.write("\turl: " + str(item[1]["url"]) + "\n")
|
||||||
@@ -6,7 +6,7 @@ from nltk.tokenize import RegexpTokenizer
|
|||||||
# load pazans
|
# load pazans
|
||||||
pazansGroups = None
|
pazansGroups = None
|
||||||
|
|
||||||
pazansFileName = sys.argv[2]
|
pazansFileName = sys.argv[1]
|
||||||
with open(pazansFileName) as file:
|
with open(pazansFileName) as file:
|
||||||
pazansGroups = json.loads(file.read())
|
pazansGroups = json.loads(file.read())
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ statusStats = dict()
|
|||||||
tokenizer = RegexpTokenizer(r"[A-Za-zА-Яа-я]+")
|
tokenizer = RegexpTokenizer(r"[A-Za-zА-Яа-я]+")
|
||||||
stemmer = RussianStemmer()
|
stemmer = RussianStemmer()
|
||||||
|
|
||||||
usersFileName = sys.argv[1]
|
usersFileName = sys.argv[2]
|
||||||
with open(usersFileName) as file:
|
with open(usersFileName) as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
user = json.loads(line)
|
user = json.loads(line)
|
||||||
|
|||||||
Reference in New Issue
Block a user