CaesarCloudSync commited on
Commit
1d6de29
·
1 Parent(s): b60ee04

schedule test

Browse files
Files changed (3) hide show
  1. main.py +23 -17
  2. raspsendemail.py +3 -3
  3. revisionbankscheduler.py +4 -4
main.py CHANGED
@@ -38,6 +38,7 @@ import pytesseract
38
  from forgotpassemail import forgotpasswordemail
39
  from RevisionBankModels import *
40
  from fastapi_utils.tasks import repeat_every
 
41
  from revisionbankscheduler import RevisionBankScheduler
42
  app = FastAPI()
43
  app.add_middleware(
@@ -97,7 +98,7 @@ async def index():
97
 
98
 
99
  @app.on_event("startup")
100
- @repeat_every(seconds= time_hour * 0.05 ) # 24 hours 24
101
  async def revisionbankschedulerevisioncardsrepeat() -> None:
102
  revisionbankschedule.runschedule()
103
  print("All Cards sent.")
@@ -473,7 +474,8 @@ async def sendnowrevisioncard(data : JSONStructure = None, authorization: str =
473
  data = dict(data)#request.get_json()
474
  now = datetime.now().strftime("%c")
475
  message = f"""{data['revisioncards'][0]['revisioncardtitle']}{data["revisioncards"][0]["revisioncard"]}"""
476
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":data["sendtoemail"],"message":message,"subject":f"{data['revisioncards'][0]['subject']} Send Now"}})
 
477
  #print(response.text)
478
  #msg = Message(f"{data['revisioncards'][0]['subject']} Send Now", recipients=[data["sendtoemail"]]) # "[email protected]"
479
  #msg.body = f"Mail from RevisionCard Send Now at {now}"
@@ -610,8 +612,9 @@ async def fmathsqp(data : JSONStructure = None, authorization: str = Header(None
610
  <h1>The Further Maths question papers links:</h1>
611
  <p>{linkmessage}</p>.
612
  """
613
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathqp PDFs"}})
614
-
 
615
  #msg = Message("FMathqp PDFs", recipients=[email]) # "[email protected]"
616
  #msg.body = f"Mail from FMathqp at {now}"
617
  #msg.html = f"""
@@ -648,8 +651,8 @@ async def fmathsqp(data : JSONStructure = None, authorization: str = Header(None
648
  <h1>The Further Maths question papers links:</h1>
649
  <p>{linkmessage}</p>.
650
  """
651
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathqp PDFs"}})
652
-
653
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
654
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
655
  if platform == "app":
@@ -743,8 +746,8 @@ async def fmathsb(data : JSONStructure = None, authorization: str = Header(None)
743
  <h1>The Further Maths Solution Bank links:</h1>
744
  <p>{linkmessage}</p>.
745
  """
746
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathSB PDFs"}})
747
-
748
  #msg = Message("FMathSB PDFs", recipients=[email]) # "[email protected]"
749
  #msg.body = f"Mail from FMathsb at {now}"
750
  #msg.html = f"""
@@ -782,8 +785,8 @@ async def fmathsb(data : JSONStructure = None, authorization: str = Header(None)
782
  <h1>The Further Maths Solution Bank links:</h1>
783
  <p>{linkmessage}</p>.
784
  """
785
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathSB PDFs"}})
786
-
787
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
788
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
789
  if platform == "app":
@@ -845,8 +848,8 @@ async def scienceocranswers(data : JSONStructure = None, authorization: str = He
845
  <h1>OCR Science {query} Answers:</h1>
846
  <p>{answerlink}</p>.
847
  """
848
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"OCR {query} Answers"}})
849
-
850
  #msg = Message(f"OCR {query} Answers", recipients=[email]) # "[email protected]"
851
  #msg.body = f"Mail from {query} at {now}"
852
  #msg.html = f"""
@@ -873,7 +876,8 @@ async def scienceocranswers(data : JSONStructure = None, authorization: str = He
873
  <h1>OCR Science {query} Answers:</h1>
874
  <p>{answerlink}</p>.
875
  """
876
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"OCR {query} Answers"}})
 
877
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
878
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
879
  result = {"scienceocranswers": answerlink,"emailcount":int(user_from_db["emailsleft"])-1,"end_date_subscription":9999999}
@@ -917,7 +921,8 @@ async def physicsaqa(data : JSONStructure = None, authorization: str = Header(No
917
  <p>{questionpaper}</p>
918
  <p>{markscheme}</p>.
919
  """
920
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"PhysicsAqa Papers"}})
 
921
  #msg = Message(f"PhysicsAqa Papers", recipients=[email]) # "[email protected]"
922
  #msg.body = f"Mail from physicsaqaApi at {now}"
923
  #msg.html = f"""
@@ -944,8 +949,8 @@ async def physicsaqa(data : JSONStructure = None, authorization: str = Header(No
944
  <p>{questionpaper}</p>
945
  <p>{markscheme}</p>.
946
  """
947
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"PhysicsAqa Papers"}})
948
-
949
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
950
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
951
  return {"physicsaqa":{"chapter":chapter,"topic":topic,"question paper":questionpaper,"markscheme":markscheme,"emailcount":int(user_from_db["emailsleft"])-1,"end_date_subscription":9999999}}
@@ -1027,7 +1032,8 @@ async def forgotpassword(data : JSONStructure = None, authorization: str = Heade
1027
  access_token = secure_decode(data["email"]) #create_access_token(identity=data["email"])
1028
  # store token in database temporarily
1029
  now = datetime.now().strftime("%c")
1030
- response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":data["email"],"message":forgotpasswordemail(data["email"],access_token),"subject":f"RevsionBank Password Reset"}})
 
1031
  #msg = Message(f"RevsionBank Password Reset", recipients=[data["email"]]) # "[email protected]"
1032
  #msg.body = f"Mail from RevisionBank at {now}"
1033
  #msg.html = forgotpasswordemail(data["email"],access_token)
 
38
  from forgotpassemail import forgotpasswordemail
39
  from RevisionBankModels import *
40
  from fastapi_utils.tasks import repeat_every
41
+ from raspsendemail import RaspEmail
42
  from revisionbankscheduler import RevisionBankScheduler
43
  app = FastAPI()
44
  app.add_middleware(
 
98
 
99
 
100
  @app.on_event("startup")
101
+ @repeat_every(seconds= time_hour * 2 ) # 24 hours 24
102
  async def revisionbankschedulerevisioncardsrepeat() -> None:
103
  revisionbankschedule.runschedule()
104
  print("All Cards sent.")
 
474
  data = dict(data)#request.get_json()
475
  now = datetime.now().strftime("%c")
476
  message = f"""{data['revisioncards'][0]['revisioncardtitle']}{data["revisioncards"][0]["revisioncard"]}"""
477
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":data["sendtoemail"],"message":message,"subject":f"{data['revisioncards'][0]['subject']} Send Now"}})
478
+ RaspEmail.send(**{"email":data["sendtoemail"],"message":message,"subject":f"{data['revisioncards'][0]['subject']} Send Now"})
479
  #print(response.text)
480
  #msg = Message(f"{data['revisioncards'][0]['subject']} Send Now", recipients=[data["sendtoemail"]]) # "[email protected]"
481
  #msg.body = f"Mail from RevisionCard Send Now at {now}"
 
612
  <h1>The Further Maths question papers links:</h1>
613
  <p>{linkmessage}</p>.
614
  """
615
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathqp PDFs"}})
616
+ RaspEmail.send(**{"email":email,"message":message,"subject":"FMathqp PDFs"})
617
+
618
  #msg = Message("FMathqp PDFs", recipients=[email]) # "[email protected]"
619
  #msg.body = f"Mail from FMathqp at {now}"
620
  #msg.html = f"""
 
651
  <h1>The Further Maths question papers links:</h1>
652
  <p>{linkmessage}</p>.
653
  """
654
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathqp PDFs"}})
655
+ RaspEmail.send(**{"email":email,"message":message,"subject":"FMathqp PDFs"})
656
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
657
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
658
  if platform == "app":
 
746
  <h1>The Further Maths Solution Bank links:</h1>
747
  <p>{linkmessage}</p>.
748
  """
749
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathSB PDFs"}})
750
+ RaspEmail.send(**{"email":email,"message":message,"subject":"FMathSB PDFs"})
751
  #msg = Message("FMathSB PDFs", recipients=[email]) # "[email protected]"
752
  #msg.body = f"Mail from FMathsb at {now}"
753
  #msg.html = f"""
 
785
  <h1>The Further Maths Solution Bank links:</h1>
786
  <p>{linkmessage}</p>.
787
  """
788
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":"FMathSB PDFs"}})
789
+ RaspEmail.send(**{"email":email,"message":message,"subject":"FMathSB PDFs"})
790
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
791
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
792
  if platform == "app":
 
848
  <h1>OCR Science {query} Answers:</h1>
849
  <p>{answerlink}</p>.
850
  """
851
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"OCR {query} Answers"}})
852
+ RaspEmail.send(**{"email":email,"message":message,"subject":f"OCR {query} Answers"})
853
  #msg = Message(f"OCR {query} Answers", recipients=[email]) # "[email protected]"
854
  #msg.body = f"Mail from {query} at {now}"
855
  #msg.html = f"""
 
876
  <h1>OCR Science {query} Answers:</h1>
877
  <p>{answerlink}</p>.
878
  """
879
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"OCR {query} Answers"}})
880
+ RaspEmail.send(**{"email":email,"message":message,"subject":f"OCR {query} Answers"})
881
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
882
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
883
  result = {"scienceocranswers": answerlink,"emailcount":int(user_from_db["emailsleft"])-1,"end_date_subscription":9999999}
 
921
  <p>{questionpaper}</p>
922
  <p>{markscheme}</p>.
923
  """
924
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"PhysicsAqa Papers"}})
925
+ RaspEmail.send(**{"email":email,"message":message,"subject":f"PhysicsAqa Papers"})
926
  #msg = Message(f"PhysicsAqa Papers", recipients=[email]) # "[email protected]"
927
  #msg.body = f"Mail from physicsaqaApi at {now}"
928
  #msg.html = f"""
 
949
  <p>{questionpaper}</p>
950
  <p>{markscheme}</p>.
951
  """
952
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":email,"message":message,"subject":f"PhysicsAqa Papers"}})
953
+ RaspEmail.send(**{"email":email,"message":message,"subject":f"PhysicsAqa Papers"})
954
  user_from_db.update({"emailsleft":int(user_from_db["emailsleft"])-1})
955
  importcsv.db.studentsubscriptions.update_one({"email": current_user}, {"$set": user_from_db},upsert=True)
956
  return {"physicsaqa":{"chapter":chapter,"topic":topic,"question paper":questionpaper,"markscheme":markscheme,"emailcount":int(user_from_db["emailsleft"])-1,"end_date_subscription":9999999}}
 
1032
  access_token = secure_decode(data["email"]) #create_access_token(identity=data["email"])
1033
  # store token in database temporarily
1034
  now = datetime.now().strftime("%c")
1035
+ #response = requests.post("http://0.0.0.0:7860/raspsendemail",json={"raspsendemail":{"email":data["email"],"message":forgotpasswordemail(data["email"],access_token),"subject":f"RevsionBank Password Reset"}})
1036
+ RaspEmail.send(**{"email":data["email"],"message":forgotpasswordemail(data["email"],access_token),"subject":f"RevsionBank Password Reset"})
1037
  #msg = Message(f"RevsionBank Password Reset", recipients=[data["email"]]) # "[email protected]"
1038
  #msg.body = f"Mail from RevisionBank at {now}"
1039
  #msg.html = forgotpasswordemail(data["email"],access_token)
raspsendemail.py CHANGED
@@ -7,17 +7,17 @@ from email.mime.text import MIMEText
7
 
8
  class RaspEmail:
9
  @staticmethod
10
- def send(receiver_email,subject,htmlmessage,attachment=None):
11
  sender_email = "[email protected]"
12
  message = MIMEMultipart("alternative")
13
  message["Subject"] = subject
14
  message["From"] = sender_email
15
- message["To"] = receiver_email
16
  password = "ktqgjfzgcbfacsve"
17
 
18
 
19
  # Turn these into plain/html MIMEText objects
20
- part1 = MIMEText(htmlmessage, "html")
21
 
22
  # Add HTML/plain-text parts to MIMEMultipart message.
23
  # The email client will try to render the last part first
 
7
 
8
  class RaspEmail:
9
  @staticmethod
10
+ def send(email,subject,message,attachment=None):
11
  sender_email = "[email protected]"
12
  message = MIMEMultipart("alternative")
13
  message["Subject"] = subject
14
  message["From"] = sender_email
15
+ message["To"] = email
16
  password = "ktqgjfzgcbfacsve"
17
 
18
 
19
  # Turn these into plain/html MIMEText objects
20
+ part1 = MIMEText(message, "html")
21
 
22
  # Add HTML/plain-text parts to MIMEMultipart message.
23
  # The email client will try to render the last part first
revisionbankscheduler.py CHANGED
@@ -9,7 +9,7 @@ class RevisionBankScheduler:
9
  def sendimagecard(self,user,card):
10
  imagecardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}
11
  ##print(user["sendtoemail"])
12
- RaspEmail.send(receiver_email = imagecardjson["email"],subject = imagecardjson["subject"],htmlmessage = imagecardjson["message"],attachment = imagecardjson["attachment"])
13
 
14
  #response = requests.post("https://revisionbank-email.onrender.com/raspsendemail",json={"raspsendemail":{"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}})
15
 
@@ -21,7 +21,7 @@ class RevisionBankScheduler:
21
  textcardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"]}
22
  #print(textcardjson["attachment"])
23
  #print(textcardjson)
24
- RaspEmail.send(receiver_email = textcardjson["email"],subject = textcardjson["subject"],htmlmessage = textcardjson["message"])#,attachment = textcardjson["attachment"])
25
 
26
  #sendgrid_send(user["sendtoemail"],f"{card['revisioncardtitle']}\n{card['revisioncard']}",card["subject"])
27
  #print(response.text)
@@ -121,7 +121,7 @@ class RevisionBankScheduler:
121
  if "revisioncardimage" in card:
122
  #print([{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}])
123
  imagecardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}
124
- RaspEmail.send(receiver_email = imagecardjson["email"],subject = imagecardjson["subject"],htmlmessage = imagecardjson["message"],attachment = imagecardjson["attachment"])
125
 
126
  #response = requests.post("https://revisionbank-email.onrender.com/raspsendemail",json={"raspsendemail":{"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}})
127
  #sendgrid_send(user["sendtoemail"],f"{card['revisioncardtitle']}\n{card['revisioncard']}",card["subject"])
@@ -129,7 +129,7 @@ class RevisionBankScheduler:
129
  elif "revisioncardimage" not in card:
130
  #response = requests.post("https://revisionbank-email.onrender.com/raspsendemail",json={"raspsendemail":{"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"]}})
131
  textcardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"]}
132
- RaspEmail.send(receiver_email = textcardjson["email"],subject = textcardjson["subject"],htmlmessage = textcardjson["message"],attachment = textcardjson["attachment"])
133
 
134
  #sendgrid_send(user["sendtoemail"],f"{card['revisioncardtitle']}\n{card['revisioncard']}",card["subject"])
135
  print("Traffic light card sent.")
 
9
  def sendimagecard(self,user,card):
10
  imagecardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}
11
  ##print(user["sendtoemail"])
12
+ RaspEmail.send(email = imagecardjson["email"],subject = imagecardjson["subject"],message = imagecardjson["message"],attachment = imagecardjson["attachment"])
13
 
14
  #response = requests.post("https://revisionbank-email.onrender.com/raspsendemail",json={"raspsendemail":{"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}})
15
 
 
21
  textcardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"]}
22
  #print(textcardjson["attachment"])
23
  #print(textcardjson)
24
+ RaspEmail.send(email = textcardjson["email"],subject = textcardjson["subject"],message = textcardjson["message"])#,attachment = textcardjson["attachment"])
25
 
26
  #sendgrid_send(user["sendtoemail"],f"{card['revisioncardtitle']}\n{card['revisioncard']}",card["subject"])
27
  #print(response.text)
 
121
  if "revisioncardimage" in card:
122
  #print([{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}])
123
  imagecardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}
124
+ RaspEmail.send(email = imagecardjson["email"],subject = imagecardjson["subject"],message = imagecardjson["message"],attachment = imagecardjson["attachment"])
125
 
126
  #response = requests.post("https://revisionbank-email.onrender.com/raspsendemail",json={"raspsendemail":{"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"],"attachment":[{card["revisioncardimgname"][0]:card["revisioncardimage"][0]}]}})
127
  #sendgrid_send(user["sendtoemail"],f"{card['revisioncardtitle']}\n{card['revisioncard']}",card["subject"])
 
129
  elif "revisioncardimage" not in card:
130
  #response = requests.post("https://revisionbank-email.onrender.com/raspsendemail",json={"raspsendemail":{"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"]}})
131
  textcardjson = {"email":user["sendtoemail"],"message":f"{card['revisioncardtitle']}\n{card['revisioncard']}","subject":card["subject"]}
132
+ RaspEmail.send(email = textcardjson["email"],subject = textcardjson["subject"],message = textcardjson["message"],attachment = textcardjson["attachment"])
133
 
134
  #sendgrid_send(user["sendtoemail"],f"{card['revisioncardtitle']}\n{card['revisioncard']}",card["subject"])
135
  print("Traffic light card sent.")