from teleskop_models.mongo import Account, NewStream, Users from application.teleskop.settings.common import MONGO_URL from mongoengine import connect import datetime print(MONGO_URL) connect(host=MONGO_URL) ###################### all_list = [] def get_user_by_account_id(account_id): print(account_id) user = Users.objects(account=account_id, permission='61e0e648c52c4a668f77bcaf').first() return user # def get_streams_by_account_id(account_id): # streams = NewStream.objects(account=account_id) # return streams start_date = datetime.datetime.strptime('2023-03-21', '%Y-%m-%d') end_date = datetime.datetime.strptime('2023-03-31', '%Y-%m-%d') accounts = Account.objects(created_at__gte=start_date, created_at__lte=end_date) for _id, account in enumerate(accounts): print(_id, account.id) user = get_user_by_account_id(account.id) if user.email.endswith('@teleskop.app'): continue if user.email.endswith('@forceremove.com'): continue # streams = get_streams_by_account_id(account.id) # all_keywords = [] # all_positive_keywords = [] # all_negative_keywords = [] # all_twitter_users = [] # all_intagram_users = [] # all_facebook_users = [] # all_stream_names = [] # for stream in streams: # all_keywords.extend(stream.main_keywords) # all_positive_keywords.extend(stream.relevant_keywords) # all_negative_keywords.extend(stream.negative_keywords) # all_twitter_users.extend(stream.twitter_usernames) # all_intagram_users.extend(stream.instagram_usernames) # all_facebook_users.extend(stream.facebook_usernames) # all_stream_names.append(stream.name) all_list.append({ 'Oluşturulma Tarihi': account.created_at.strftime('%Y-%m-%d %H:%M:%S'), 'Hesap İsmi': account.account_name, 'İsim': user.first_name, 'Soyisim': user.last_name, 'Telefon': user.mobile, 'EMail': user.email, 'Email Onayı': user.email_confirmed, "Son Giriş": user.last_login_date.strftime('%Y-%m-%d %H:%M:%S'), 'Son İşlem': user.is_online.strftime('%Y-%m-%d %H:%M:%S'), # 'Toplam Akış Sayısı': len(all_stream_names), # 'Tüm Akış İsimleri': str(all_stream_names), # # 'Tüm Kelimeler': str(all_keywords), # 'Tüm Pozitif Kelimeler': str(all_positive_keywords), # 'Tüm Negatif Kelimeler': str(all_negative_keywords), # 'Tüm Twitter Kullanıcıları': str(all_twitter_users), # 'Tüm Instagram Kullanıcıları': str(all_intagram_users), # 'Tüm Facebook Kullanıcıları': str(all_facebook_users), }) import json print(len(all_list)) json_obj = json.dumps(all_list, indent=4) # save the object to file with open('data.json', 'w') as f: f.write(json_obj)