Exemplo n.º 1
0
 def log_staging_deploy(msg):
     pattern = re.compile("finished deploying branch.* version.* to staging")
     if pattern.findall(msg):
         version = msg.split("branch")[1].split("version")[0].strip()
         database = Database()
         database.initialize()
         database.insert(collection="version_record",
                         data={
                             "version": version,
                             "time": int(time.time())
                         })
Exemplo n.º 2
0
 def add_fact(fact_type, fact_text):
     if not any([(fact_type == "puppy_fact"),
                 (fact_type == "cat_fact"),
                 (fact_type == "horse_fact")]):
         print("fact_type must be one of the following: puppy_fact, cat_fact, horse_fact")
     else:
         database = Database()
         database.initialize()
         fact = Facts(fact_type = fact_type, fact_text = fact_text)
         database.insert("facts", fact.json())
         print("Fact successfully added")
Exemplo n.º 3
0
 def add_token(self, auth_response):
     database = Database()
     database.initialize()
     self.access_token = auth_response['bot']['bot_access_token']
     self.user_id = auth_response['user_id']
     self.team_id = auth_response['team_id']
     numbers = re.compile('\d+(?:\.\d+)?')
     max_age = int(
         numbers.findall(
             auth_response['headers']['Strict-Transport-Security'])[0])
     self.token_expiry_time = int(time.time()) + max_age
     database.insert(collection="slack_tokens", data=self.json())
Exemplo n.º 4
0
 def migrate_facts():
     dirpath = os.path.dirname(__file__)
     fact_files = {'horse_fact': 'facts/horse_facts.txt',
                   'cat_fact': 'facts/cat_facts.txt',
                   'puppy_fact': 'facts/puppy_facts.txt'}
     database = Database()
     database.initialize()
     for k, v in fact_files.items():
         lines = open(os.path.join(dirpath, v)).read().splitlines()
         for line in lines:
             if line == "":
                 continue
             else:
                 fact = Facts(fact_type=k, fact_text=line)
                 database.insert("facts", fact.json())
Exemplo n.º 5
0
 def add_distributor(type, email_address=None, slack_ids=None):
     if "type" == "email":
         if email_address is not None:
             return "Please pass an email address"
     if "type" == "slack":
         if email_address is not None:
             return "Please pass an slack_channel_id"
     elif all([(type != "slack"), (type != "email")]):
         return "Valid 'type's are 'slack' and 'email'"
     else:
         distributor = Distributor(type=type,
                                   email_address=email_address,
                                   slack_ids=slack_ids)
         database = Database()
         database.initialize()
         database.insert("distributors", distributor.json())
Exemplo n.º 6
0
 def get_email_credentials(cls, returnless=False):
     database = Database()
     database.initialize()
     emailer_credential_object = database.find_one("emailer_credentials",
                                                   ({}))
     if emailer_credential_object is None:
         email_address = input(
             "Please enter the gmail account address you would like to use to send emails:"
         )
         email_password = input("Please enter your gmail password:"******"Login failed. Please enter your GMAIL address:")
             email_password = input("Please enter your GMAIL password:"******"emailer_credentials",
                         ({
                             "email_address": email_address,
                             "email_password": email_password
                         }))
     else:
         email_address = emailer_credential_object['email_address']
         email_password = emailer_credential_object['email_password']
     if returnless is False:
         return email_address, email_password
Exemplo n.º 7
0
 def add_entry(data):
     database = Database()
     database.initialize()
     database.insert("logging", data)
Exemplo n.º 8
0
 def add_entry(self):
     database = Database()
     database.initialize()
     database.insert("message_log", self.json())
Exemplo n.º 9
0
 def onboard_user(self):
     database = Database()
     database.initialize()
     database.insert("users", self.json())
     print("User successfully added")
Exemplo n.º 10
0
 def add_entry(self):
     database = Database()
     database.initialize()
     database.insert("samples", self.json())