Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor db_query_api.py #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions climabot/db_query_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,36 @@
group.add_argument("-u", "--user_handle", help="user handle to query")
group.add_argument("-f", "--csv_file", help="path to the csv file with the twitter handles to parse in the first (0) column")

# get variables
args = parser.parse_args()
config_db = args.mariadb_group
user_handle = args.user_handle

## the config file for mariadb databases
config = (ConfigObj(expanduser('~/.my.cnf')))
def main():
# get variables
args = parser.parse_args()
config_db = args.mariadb_group
user_handle = args.user_handle

## the config file for mariadb databases
config = (ConfigObj(expanduser('~/.my.cnf')))

db = connect(conf_db=config_db, database='hackathon')
c = db.cursor()

if args.user_handle:
## to insert just one user in the db
fill_database(args.user_handle)

elif args.csv_file:
## to insert all users from a csv
files_path = args.csv_file
twitter_handles = pd.read_csv(files_path)

count = 0
# feed that db!!
for i, row in twitter_handles.iterrows():
count += 1
import_user = (row[0][1:])
print(import_user)
fill_database(import_user)



# Setup API:
Expand Down Expand Up @@ -56,9 +79,6 @@ def connect(conf_db, database=""):
password=config[conf_db]['password'],
database=database)

db = connect(conf_db=config_db, database='hackathon')
c = db.cursor()

def fill_database(user):

# IPCC_CH
Expand Down Expand Up @@ -145,22 +165,5 @@ def fill_database(user):

db.commit()

if args.user_handle:
## to insert just one user in the db
fill_database(args.user_handle)

elif args.csv_file:
## to insert all users from a csv
files_path = args.csv_file
twitter_handles = pd.read_csv(files_path)

count = 0
# feed that db!!
for i, row in twitter_handles.iterrows():
count += 1
import_user = (row[0][1:])
print(import_user)
fill_database(import_user)



if __name__ == "__main__":
main()