-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagengagement.py
57 lines (49 loc) · 1.5 KB
/
tagengagement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pprint import pprint
import json
import os
import datetime
import operator
import sys
import getopt
import cassandra
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
cloud_config = {
'secure_connect_bundle': 'secure-connect-teaminferno.zip'
}
auth_provider = PlainTextAuthProvider('PKulaMpxCDcyZsxHoLeorxdE',
'R1KL7l1u,awPgafa0-G3Xjt5QAjk,gTtz.qgmQSrsstUIdQnOoq_jgI,77nPA9upDOOYj2+ZefBMXudz+dFfF7IYPMGo56gz7xD337Nrcaufv3KKh,kzaS,0_xuCflNI')
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
cqlsession = cluster.connect('yvideos')
def searchfortag(listofterms, session):
results = {}
title = 'tag: '
for word in listofterms:
title += word
query = "SELECT count, score FROM averages where keyval = '" + title + "'"
nameresults = session.execute(query)
score = 0
count = 0
flag = True
if nameresults is not None:
for val in nameresults:
for number in val:
if flag:
holder = val[0]
count = int(holder)
flag = False
else:
hold = val[1]
score = int(hold)
average = 0
if score > 0:
average = score / count
return average
badsearch = -1
return badsearch
searchterms = sys.argv
searchterms.pop(0)
result = searchfortag(searchterms, cqlsession)
print(result)