MCPcopy Index your code
hub / github.com/InstaPy/InstaPy / get_profile

Function get_profile

instapy/database_engine.py:143–172  ·  view source on GitHub ↗
(name, address, logger)

Source from the content-addressed store, hash-verified

141
142
143def get_profile(name, address, logger):
144 try:
145 conn = sqlite3.connect(address)
146 with conn:
147 conn.row_factory = sqlite3.Row
148 cursor = conn.cursor()
149
150 profile = select_profile_by_username(cursor, name)
151
152 if profile is None:
153 add_profile(conn, cursor, name)
154 # reselect the table after adding data to get the proper `id`
155 profile = select_profile_by_username(cursor, name)
156 except Exception as exc:
157 logger.warning(
158 "Heeh! Error occurred while getting a DB profile for '{}':\n\t{}".format(
159 name, str(exc).encode("utf-8")
160 )
161 )
162 finally:
163 if conn:
164 # close the open connection
165 conn.close()
166
167 profile = dict(profile)
168 profile_id = profile["id"]
169 # assign the id to its child in `Settings` class
170 Settings.profile["id"] = profile_id
171
172 return profile_id
173
174
175def add_profile(conn, cursor, name):

Callers 1

get_databaseFunction · 0.85

Calls 2

add_profileFunction · 0.85

Tested by

no test coverage detected