-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_script2.py
executable file
·83 lines (81 loc) · 2.23 KB
/
create_script2.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from django.contrib.auth.models import User
from users.models import *
from yap.models import *
from notifications.models import *
from stream.models import *
from location.models import *
from operator import itemgetter
import random
import datetime
import time
import csv
def make_likes():
users = list(User.objects.all())
reyaps = list(Reyap.objects.all())
for_checking = []
user_copy = users
for user in user_copy:
num_likes = random.randint(10,20)
possible_yaps = [post.yap.pk for post in Stream.objects.filter(user=user) if not post.reyap_flag]
while num_likes > 0:
if random.random() < 0.5:
target = 'reyap'
else:
target = 'yap'
print target
if target == 'reyap':
possible_reyaps = [post.yap.pk for post in Stream.objects.filter(user=user,is_active=True,reyap_flag=True)]
print possible_reyaps
if possible_reyaps == []:
print ("possible_reyaps = empty = []")
yap = None
reyap = None
reyap_flag = None
like = {
'yap' :yap,
'reyap_flag' :reyap_flag,
'reyap' :reyap,
'user' :user
}
print user.pk, yap.pk
#test = Like.objects.create(**like)
#print user.pk, yap.pk, test.original_like
print user.pk, yap.pk, like
print ("num_likes")
print num_likes
else:
print ("possible_reyaps are not empty")
reyap_chosen = random.choice(possible_reyaps)
if reyap_chosen in for_checking:
reyap_chosen = random.choice(possible_reyaps)
else:
reyap = Reyap.objects.get(pk=reyap_chosen)
print ("reyap")
print reyap
yap = reyap.yap
reyap_flag = True
if not (yap.pk,user.pk) in for_checking:
for_checking.append((yap.pk,user.pk))
fake_needed = True
try:
possible_yaps.remove(reyap.yap.pk)
except:
pass
else:
fake_needed = False
like = {
'yap' :yap,
'reyap_flag' :reyap_flag,
'reyap' :reyap,
'user' :user
}
print user.pk, yap.pk
#test = Like.objects.create(**like)
#print user.pk, yap.pk, test.original_like
print user.pk, yap.pk, like
num_likes -= 1
print ("num_likes")
print num_likes
print(str(user.pk) + " has finished")
gc.collect()
make_likes()