Spaces:
Sleeping
Sleeping
LegendaryLoona
commited on
Commit
•
6dbbaa4
1
Parent(s):
2861c0b
Update APIOstin.py
Browse files- APIOstin.py +11 -5
APIOstin.py
CHANGED
@@ -107,19 +107,25 @@ def get_comments(group_id, posts): #Gets comments, gets answers to these commen
|
|
107 |
print('Starting to retrieve names')
|
108 |
try:
|
109 |
time.sleep(15)
|
110 |
-
names = login.method("users.get", {"user_ids": str(names_ids[1:-1]), "fields": "city, country, sex", "name_case": "nom"})
|
111 |
except:
|
112 |
print("Couldn't get the names, trying again")
|
113 |
time.sleep(60)
|
114 |
-
names = login.method("users.get", {"user_ids": str(names_ids[1:-1]), "fields": "city, country, sex", "name_case": "nom"})
|
115 |
names_no_ostin = [value for value in names_ids if value > 0]
|
116 |
sub_status = login.method("groups.isMember", {"group_id": int(str(group_id)[1:]), "user_ids": str(names_no_ostin)[1:-1]})
|
|
|
117 |
SEX = {1: 'Female', 2: 'Male'}
|
118 |
for i in names:
|
119 |
try:
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
123 |
print('Generating df')
|
124 |
|
125 |
return clean_comments, clean_names
|
|
|
107 |
print('Starting to retrieve names')
|
108 |
try:
|
109 |
time.sleep(15)
|
110 |
+
names = login.method("users.get", {"user_ids": str(names_ids[1:-1]), "fields": "city, country, sex, bdate", "name_case": "nom"})
|
111 |
except:
|
112 |
print("Couldn't get the names, trying again")
|
113 |
time.sleep(60)
|
114 |
+
names = login.method("users.get", {"user_ids": str(names_ids[1:-1]), "fields": "city, country, sex, bdate", "name_case": "nom"})
|
115 |
names_no_ostin = [value for value in names_ids if value > 0]
|
116 |
sub_status = login.method("groups.isMember", {"group_id": int(str(group_id)[1:]), "user_ids": str(names_no_ostin)[1:-1]})
|
117 |
+
today = datetime.date.today()
|
118 |
SEX = {1: 'Female', 2: 'Male'}
|
119 |
for i in names:
|
120 |
try:
|
121 |
+
if not isinstance(i.get('bdate'), str):
|
122 |
+
clean_names[len(clean_names)+1] = {'ID': i.get('id'), 'First name': i.get('first_name'), 'Last name': i.get('last_name'), 'Subscriber':sub_status[len(clean_names)]["member"], 'City': i.get('city'), 'Country': i.get('country'), 'Sex': SEX[i.get('sex')], 'Age': "-"}
|
123 |
+
elif len(i.get('bdate')) >= 6:
|
124 |
+
clean_names[len(clean_names)+1] = {'ID': i.get('id'), 'First name': i.get('first_name'), 'Last name': i.get('last_name'), 'Subscriber':sub_status[len(clean_names)]["member"], 'City': i.get('city'), 'Country': i.get('country'), 'Sex': SEX[i.get('sex')], 'Age': (int(today.year) - int(i.get('bdate')[-4:]))}
|
125 |
+
else:
|
126 |
+
clean_names[len(clean_names)+1] = {'ID': i.get('id'), 'First name': i.get('first_name'), 'Last name': i.get('last_name'), 'Subscriber':sub_status[len(clean_names)]["member"], 'City': i.get('city'), 'Country': i.get('country'), 'Sex': SEX[i.get('sex')], 'Age': "-"}
|
127 |
+
except Exception as ex:
|
128 |
+
print(f'Error in names\n {ex}')
|
129 |
print('Generating df')
|
130 |
|
131 |
return clean_comments, clean_names
|