| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -41,14 +41,15 @@ class WebPushService(): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:////app/instance/data/webpush.db') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # This relative path works in docker-compose | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        #db_uri = os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:///data/webpush.db') | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        self.app.config['SQLALCHEMY_DATABASE_URI'] = db_uri | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#        self.app.config['SQLALCHEMY_DATABASE_URI'] = db_uri | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # Initializing the database with the application | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        db.init_app(self.app) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#        db.init_app(self.app) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#        db.create_all() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # Creating a context for the application and initializing services | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        with self.app.app_context(): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            self._initialize() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#        with self.app.app_context(): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					#            self._initialize() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # Creating and starting a thread to send daily notifications | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        self.daily_notification_thread = threading.Thread(target=self._send_daily_notifications) | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -109,6 +110,7 @@ class WebPushService(): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          to web clients, hence the check and generation if they don't exist. | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        """ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        pass | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # Checking if there are any VAPID keys in the database | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if not VAPIDKey.query.first(): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -170,26 +172,26 @@ class WebPushService(): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            # Creating a context for the application to enable database operations | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            with self.app.app_context(): | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                pass | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                # Retrieving all subscription data from the database | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                all_subscriptions = Subscription.query.all() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #all_subscriptions = Subscription.query.all() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                # Retrieving the VAPID key from the database | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                vapid_key = VAPIDKey.query.first() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #vapid_key = VAPIDKey.query.first() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                # Constructing the push notification message | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                message = {"title": "Daily Update", "message": "Here's your daily update!"} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #message = {"title": "Daily Update", "message": "Here's your daily update!"} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                # Sending a push notification to each subscribed client | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                for subscription in all_subscriptions: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    subscription_info = { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        "endpoint": subscription.endpoint, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        "keys": { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            "p256dh": subscription.p256dh, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                            "auth": subscription.auth | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    WebPushService._send_push_notification(subscription_info, message, vapid_key) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                # for subscription in all_subscriptions: | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #     subscription_info = { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #         "endpoint": subscription.endpoint, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #         "keys": { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #             "p256dh": subscription.p256dh, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #             "auth": subscription.auth | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #         } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #     } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                #     WebPushService._send_push_notification(subscription_info, message, vapid_key) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            # Sleeping for 24 hours before sending the next set of notifications | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            time.sleep(24 * 60 * 60) | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |