Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymongo
- from dynaconf import Dynaconf
- settings = Dynaconf(
- settings_files=['settings.yaml']
- )
- client = pymongo.MongoClient(
- f"mongodb://"
- f"{settings.mongo.username}:{settings.mongo.password}@"
- f"{settings.mongo.host}:{settings.mongo.port}"
- )
- db = client["idied"]
- users_collection = db["authorized_users"]
- notes_collection = db["notes"]
- date_expression = (
- "Math.floor(Date.now() / 1000) - "
- "this.last_online_timestamp > 60"
- )
- def get_users_away_for_30_days() -> list:
- users = users_collection.find(
- {
- "$where": date_expression,
- "has_died": False
- },
- {"_id": 0, "user_id": 1}
- )
- users = list(users)
- users = [ user.values() for user in users ]
- users = [ list(user) for user in users ]
- users = [ user[0] for user in users ]
- return users
- def update_databases(users_away_for_30_days):
- if not users_away_for_30_days:
- return
- notes_collection.update_many(
- {
- "user_id": {"$in": users_away_for_30_days}
- },
- {
- "$set": {
- "is_accessible": True
- }
- }
- )
- users_collection.update_many(
- {
- "user_id": {"$in": users_away_for_30_days}
- },
- {
- "$set": {
- "has_died": True
- }
- }
- )
- if __name__ == "__main__":
- print("Launching...")
- users_away_for_30_days = get_users_away_for_30_days()
- update_databases(users_away_for_30_days)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement