def save_json_sms(json_sms): """ Args: json_sms: Returns: """ sms_fetch = list(Sms().findBy({ "from_number": json_sms["from_number"], "message": json_sms["message"], "date": json_sms["date"] })) if len(sms_fetch) == 0: print("{+} Saving json_sms: ", json_sms) new_sms = Sms(json_sms) new_sms.save()
def perform_command(to_update, phone, command, body): results, array_resp, to_search = "", [], body[:25] if command.lower() in ALLOWED_COMMAND: if "#google" in command.lower(): print("[+] Search for :", to_search) results = search(to_search, 3) if "#wiki" in command.lower(): print("[+] Wikipedia for :", to_search) results = wikki(to_search) print("[+] results: ", results) if len(results) > 5: chunks = string_divide(results, 200) for chunk in chunks: print("[+] Sending :", chunk) try_send_sms(phone, chunk) else: try_send_sms(phone, "Any relevant results, try another search !") print("[+] Any relevant results, try another search !") print("[+]Update Made in the database !") to_update["command"]["status"] = True print("to_update:", to_update) Sms().update({ "from_number": phone, "command.label": command, "command.body": body }, to_update)
def get_commands(pending=False): """ Args: pending: At true it will return pending command Returns: """ return perform_fetch(Sms().findBy({"command.status": pending}))
def get_all_commands(): """ Returns: """ return perform_fetch(Sms().findBy({"command.status": {"$exists": True}}))
def get_only_messages(): """ Returns: """ return perform_fetch(Sms().findBy({"command.status": {"$exists": False}}))
def perform_fetch(find_request=None): if find_request is None: find_request = Sms().findAll() try: list_sms = list(find_request) for row in list_sms: del row['_id'] return list_sms except Exception as es: print(es) return []
from receive import erase_all_sms from models.Sms import Sms Sms().delete({}) print(erase_all_sms())