|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import json |
|
import os |
|
import time |
|
|
|
|
|
from pprint import pprint |
|
import requests |
|
|
|
|
|
def request_linear( |
|
headers, data, url="https://api.linear.app/graphql", print_header=False |
|
): |
|
response_data = None |
|
try: |
|
response = requests.post(url, headers=headers, json=data) |
|
|
|
response_data = response.json() |
|
if print_header: |
|
print("--- ヘッダーの表示開始 ---") |
|
pprint(dict(response.headers), indent=4) |
|
print("--- ヘッダーの表示終了 ---") |
|
|
|
response.raise_for_status() |
|
return response_data |
|
except requests.exceptions.RequestException as e: |
|
print(response_data) |
|
print(f"エラーが発生しました: {e}") |
|
exit(0) |
|
except json.JSONDecodeError as e: |
|
print(f"JSONデコードエラー: {e}") |
|
print(f"レスポンス内容:\n{response.text}") |
|
exit(0) |
|
|
|
|
|
def load_api_key(dir="./"): |
|
print(f"{dir}.env") |
|
from dotenv import load_dotenv |
|
|
|
load_dotenv(dotenv_path=f"{dir}.env") |
|
if "api_key" in os.environ: |
|
api_key = os.environ["api_key"] |
|
return api_key |
|
else: |
|
print("'api_key' が環境変数にありません。") |
|
print(".envファイルを作成し 以下の行を追加してください。") |
|
print("api_key=your_api_key") |
|
print("このファイルは.gitignoreに追加して、決して公開しないでください。") |
|
print( |
|
"Linear Settings Security&access - Personal API keysからAPI Keyは作成できます。" |
|
) |
|
exit(0) |
|
|
|
|
|
def execute_query(label, query_text, authorization, print_header=False): |
|
headers = { |
|
"Content-Type": "application/json", |
|
"Authorization": authorization, |
|
} |
|
|
|
start_time_total = time.time() |
|
print(f"--- 処理の開始:{label} ({time.strftime('%Y-%m-%d %H:%M:%S')}) ---") |
|
|
|
query_dic = {"query": query_text} |
|
print("--- クエリの表示開始 ---") |
|
print(f"{query_dic['query']}") |
|
print("--- クエリの表示終了 ---") |
|
result = request_linear(headers, query_dic, print_header=print_header) |
|
print("--- 結果の表示開始 ---") |
|
print(json.dumps(result, indent=2, ensure_ascii=False)) |
|
print("--- 結果の表示終了 ---") |
|
end_time_total = time.time() |
|
total_time = end_time_total - start_time_total |
|
print(f"--- 処理の終了:{label} ---") |
|
print(f"合計処理時間: {total_time:.4f} 秒") |
|
|
|
print("") |
|
|
|
return result |
|
|