def set_linked_url(jira_id, jama_id): #initiate the admin sync user session = connection() session.initiate_jama(os.environ["JAMA_SYNC_ORG"], os.environ["JAMA_SYNC_USERNAME"], os.environ["JAMA_SYNC_PASSWORD"]) session.initiate_jira(os.environ["JIRA_SYNC_ORG"], os.environ["JIRA_SYNC_USERNAME"], os.environ["JIRA_SYNC_PASSWORD"]) jira_res = session.jira_connection.get_issue(jira_id) #Build up the Jira URL jira_url = "https://" + os.environ[ "JIRA_SYNC_ORG"] + ".atlassian.net/browse/" + jira_res["key"] #build up the jama item URL because the jama API doesn't provide it jama_project_id = session.get_jama_item(jama_id, ["project"]) jama_url = "https://" + os.environ[ "JAMA_SYNC_ORG"] + ".jamacloud.com/perspective.req#/items/" jama_url = jama_url + str(jama_id) + "?projectId=" + str( jama_project_id["project"]) #set the Jira URL field in the jama item session.set_jama_item(jama_id, {"Jira_URL$29": jira_url}) #set the jama URL field in the jama item session.set_jira_item(jira_id, {"customfield_10029": jama_url}) return True
def delete(self): """ Delete associated record :return: True on success """ object_key = getattr(self, self._object_key) with connection(self._cache_db) as conn: conn.delete(object_key)
def read(self, object_key): """ Read data from Redis :param object_key: :return: dictionary of attributes """ read_key = self.get_cache_key(object_key) with connection(self._cache_db) as conn: raw_data = conn.get(read_key) data_dict = json.loads(raw_data) return self.from_dict(data_dict)
def query_db(self, query): try: conn = connection(config.credential) cur = conn.cursor() cur.execute(query) r = [ dict((cur.description[i][0], value) for i, value in enumerate(row)) for row in cur.fetchall() ] cur.close() return r except Exception as e: return e finally: if conn is not None: conn.close()
def write(self, exp_seconds=None): """ Write data to redis :return: True """ object_key = getattr(self, self._object_key) write_key = self.get_cache_key(object_key) if exp_seconds is not None: expiration_seconds = exp_seconds elif self._exp_seconds is not None: expiration_seconds = self._exp_seconds else: expiration_seconds = None with connection(self._cache_db) as conn: if expiration_seconds is None: conn.set(write_key, self.serialize()) else: conn.setex(write_key, self.serialize(), expiration_seconds) return True
def admin_sync(): print("starting all item sync") start_time = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%f%z') session = connection() session.initiate_jama(os.environ["JAMA_SYNC_ORG"], os.environ["JAMA_SYNC_USERNAME"], os.environ["JAMA_SYNC_PASSWORD"]) session.initiate_jira(os.environ["JIRA_SYNC_ORG"], os.environ["JIRA_SYNC_USERNAME"], os.environ["JIRA_SYNC_PASSWORD"]) db_path = os.path.join(os.path.dirname(os.getcwd()), path_to_db) items_table = database.ItemsTableOps(db_path) success = True linked_items = items_table.get_linked_items() count = 0 for item in linked_items: count += 1 try: sync_one_item(item[0], session) except: logging.error("Something failed when syncing item ID:" + str(item[0])) end_time = datetime.now( timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%f%z') sync_table = database.SyncInformationTableOps(db_path) sync_table.insert_new_sync( start_time, end_time, 0, "Something failed when syncing item ID:" + str(item[0])) success = False end_time = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%S.%f%z') sync_table = database.SyncInformationTableOps(db_path) sync_table.insert_new_sync(start_time, end_time, 1, "Synced " + str(count) + " items") return success
"JIRA_SYNC_ORG"] + ".atlassian.net/browse/" + jira_res["key"] #build up the jama item URL because the jama API doesn't provide it jama_project_id = session.get_jama_item(jama_id, ["project"]) jama_url = "https://" + os.environ[ "JAMA_SYNC_ORG"] + ".jamacloud.com/perspective.req#/items/" jama_url = jama_url + str(jama_id) + "?projectId=" + str( jama_project_id["project"]) #set the Jira URL field in the jama item session.set_jama_item(jama_id, {"Jira_URL$29": jira_url}) #set the jama URL field in the jama item session.set_jira_item(jira_id, {"customfield_10029": jama_url}) return True if __name__ == '__main__': session = connection() session.initiate_jama(os.environ["JAMA_SYNC_ORG"], os.environ["JAMA_SYNC_USERNAME"], os.environ["JAMA_SYNC_PASSWORD"]) session.initiate_jira(os.environ["JIRA_SYNC_ORG"], os.environ["JIRA_SYNC_USERNAME"], os.environ["JIRA_SYNC_PASSWORD"]) sync_one_item("10040", session) sync_all(session)
import connections import re from flask import Flask, render_template, request import time print(time) app = Flask(__name__) c, conn = connections.connection() halls = [] @app.route('/') def hello_world(): c.execute("SELECT hall_name FROM hall") cc = c.fetchall() hall_names = [] for c1 in cc: hall_names.append(''.join(c1)) print(''.join(c1)) print(hall_names) global halls halls = hall_names return render_template('home.html', hall_names=halls) class event: def __init__(self, name, location, time): self.name = name self.location = location
def main(): #Python MySql CRUD Operations #connect to DB mydb = connections.connection("localhost", "root", "admin") myCursor = connections.cursor(mydb) #create DB operations.createDatabase(myCursor, "Employees") #create table operations.createTable(myCursor, "Employees", "EmployeesMaster", id="VARCHAR(255)", name="VARCHAR(255)", phone="VARCHAR(255)") #Insert table operations.insertInTable(myCursor, "Employees", "EmployeesMaster", id="1", name="TheRock", phone="+016 3334454") #Select table operations.getTable(myCursor, "Employees", "EmployeesMaster") #Insert table operations.insertInTable(myCursor, "Employees", "EmployeesMaster", "2", "JohnCena", "+016 4444454") #Select table operations.getTable(myCursor, "Employees", "EmployeesMaster") #Select table with condition operations.getTableWithParam(myCursor, "Employees", "EmployeesMaster", id="1") #Select table with condition operations.getTableWithParam(myCursor, "Employees", "EmployeesMaster", id="1", name="\"TheRock\"") #Update table with condition operations.updateTable(myCursor, "Employees", "EmployeesMaster", {"id": "1"}, id="3", name="\"Spiderman\"") #Select table with condition operations.getTableWithParam(myCursor, "Employees", "EmployeesMaster", id="3") #Delete table operations.deleteTable(myCursor, "Employees", "EmployeesMaster") #Delete DB operations.deleteDatabase(myCursor, "Employees")
neighborhood=l[3]) for l in data.Buildings ] Agame.locations += [ loc.street(expansion=l[0], name=l[1], neighborhood=l[1]) for l in data.Streets ] for n in range(len(Agame.locations)): if Agame.locations[n].name == data.connections[n][0]: for connectedlocation in data.connections[n][1].keys(): for i in Agame.locations: if i.name == connectedlocation: clobj = i break Agame.locations[n].exits.append( connections.connection(location=clobj, connectiontype=data.connections[n] [1][connectedlocation])) for investigator in data.Investigatordata: Agame.investigators.append( inv.Investigator(forename=investigator[0], surname=investigator[1], occupation=investigator[2], stamina=investigator[4], sanity=investigator[5], focus=investigator[6], items=[], allies=[], skills=[], money=0, cluetokens=0,
# Local import import connections import task_managment import errors # Connection to mysql db mydb = mysql.connector.connect(host="localhost", user="******", password="******", database="Task_manager") cursor = mydb.cursor() status = "connection" while (status == "connection"): try: user = connections.connection(cursor) except errors.WrongConnection: print("Les identifiants sont incorrectes...") new_account = input("Voulez-vous créer un nouveau compte ? ") if (new_account.lower() in "ouiyes"): user = connections.new_account(cursor) print("Création de votre compte réussie !") status = "menu" else: print("Connexion réussie") status = "menu" while (status == "menu"): print("Que voulez vous faire ?\n", \
def connect(credential): return connections.connection(credential)