Last active
September 4, 2020 22:05
-
-
Save zeikomi552/9bb7b4526e591e73952ebef6a26b1af6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
class confg_manager: | |
_file_path = ".\\config\\setting.cnf" | |
_conf_json = {} | |
def get_userconf(self): | |
self.load() | |
return self.get_userparam() | |
def save(self, user_name, password): | |
data = {} | |
data['user_param'] = [] | |
data['user_param'].append({ | |
"USERNAME": user_name, | |
"PASSWORD": password | |
}) | |
# create directory | |
os.makedirs(".\\config", exist_ok=True) | |
with open(self._file_path, 'w+') as outfile: | |
json.dump(data, outfile) | |
def load(self): | |
# check exist file | |
if os.path.exists(self._file_path): | |
# oprn json file | |
with open(self._file_path, "r") as json_file: | |
# load jason data | |
json_data = json.load(json_file) | |
# set member parameter | |
self._conf_json = json_data | |
else: | |
self.save("","") # Empty data Save | |
self.load() # Load | |
def get_userparam(self): | |
return self._conf_json['user_param'][0]['USERNAME'], self._conf_json['user_param'][0]['PASSWORD'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import pandas as pd | |
import pprint | |
import re | |
class github_api_manager: | |
GITHUB_API = "https://api.github.com" | |
def __init__(self, user_name, password): | |
""" constractor | |
Args: | |
user_name (str): [github user name] | |
password (str): [git hub user password] | |
""" | |
self.user_name = user_name | |
self.password = password | |
def get_json(self, api, debug_log = False): | |
""" request and get json file | |
Args: | |
api (str): [base url for github api v3] | |
Returns: | |
[JSON object]: [result] | |
""" | |
# 1. create url text | |
url = self.GITHUB_API + api # base url | |
# return json | |
return self.get_json_url(url, debug_log) | |
def get_json_url(self, url, debug_log = False): | |
""" request and get json file | |
Args: | |
api (str): [base url for github api v3] | |
Returns: | |
[JSON object]: [result] | |
""" | |
# 2. create session | |
session = requests.Session() | |
session.auth = (self.user_name, self.password) | |
if debug_log == True: | |
# for debug | |
print('GET ' + url) | |
# 3. GET request | |
response = session.get(url) | |
# return json | |
return response.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment