<reponame>jburke234/csgo-stat-tracker
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 30 10:06:22 2021

@author: jburke
"""

import requests
import json
from datetime import datetime
from pathlib import Path

def insert_data():
    pass

def run_query(api_key, app_id, user_id):
    # Query string template 
    query_template = 'https://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v2/?key=API_KEY&appid=APP_ID&steamid=USER_ID'
     
    query = query_template.replace('API_KEY',api_key).replace('APP_ID', app_id).replace('USER_ID', user_id)
    
    # Request info from the API
    response = requests.get(query)
    
    data = response.json()
    
    return data

##########################################################################################################
# To be replaced with call to MongoDB - User_Id DB
def combine_two_lists_no_dup(list_one, list_two):
    
    first = set(list_one)
    second = set(list_two)
    
    temp = second - first
    
    result = list_one + list(temp)
    
    return result

def read_id_file(file_path):
    
    file = open(file_path,'r')
    
    list_of_ids = list()
    
    for line in file:
        list_of_ids.append(line.replace('\n', ''))
    
    file.close()
    
    return list_of_ids

def get_user_ids():
    file_path = Path(r"steam_ids.txt")
    list_of_steamtime_ids = read_id_file(file_path) 
    
    file_path = Path(r"steam_ids_steamdb.txt")
    list_of_steamdb_ids = read_id_file(file_path) 
    
    id_list = combine_two_lists_no_dup(list_of_steamtime_ids, list_of_steamdb_ids)
    
    return id_list
##########################################################################################################

def main():
    id_list = get_user_ids()
    
    data_list = []
    
    api_key = ""
    
    app_id = "730"
    
    for user_id in id_list:
        try:
            data_list.append(run_query(api_key, app_id, user_id))
            
        except:
            # Remove from active list
            pass
            
    # Get Today's Date
    today = datetime.today().strftime('%Y-%m-%d')
    
    # Add list to key value pair where key = today's date 
    data_json = {today: data_list}
    
    # Write to file and Insert into mongodb compass


if __name__ == '__main__':
    main()
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 30 10:06:22 2021

@author: jburke
"""

import requests
import json
from datetime import datetime
from pathlib import Path

def insert_data():
    pass

def run_query(api_key, app_id, user_id):
    # Query string template 
    query_template = 'https://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v2/?key=API_KEY&appid=APP_ID&steamid=USER_ID'
     
    query = query_template.replace('API_KEY',api_key).replace('APP_ID', app_id).replace('USER_ID', user_id)
    
    # Request info from the API
    response = requests.get(query)
    
    data = response.json()
    
    return data

##########################################################################################################
# To be replaced with call to MongoDB - User_Id DB
def combine_two_lists_no_dup(list_one, list_two):
    
    first = set(list_one)
    second = set(list_two)
    
    temp = second - first
    
    result = list_one + list(temp)
    
    return result

def read_id_file(file_path):
    
    file = open(file_path,'r')
    
    list_of_ids = list()
    
    for line in file:
        list_of_ids.append(line.replace('\n', ''))
    
    file.close()
    
    return list_of_ids

def get_user_ids():
    file_path = Path(r"steam_ids.txt")
    list_of_steamtime_ids = read_id_file(file_path) 
    
    file_path = Path(r"steam_ids_steamdb.txt")
    list_of_steamdb_ids = read_id_file(file_path) 
    
    id_list = combine_two_lists_no_dup(list_of_steamtime_ids, list_of_steamdb_ids)
    
    return id_list
##########################################################################################################

def main():
    id_list = get_user_ids()
    
    data_list = []
    
    api_key = ""
    
    app_id = "730"
    
    for user_id in id_list:
        try:
            data_list.append(run_query(api_key, app_id, user_id))
            
        except:
            # Remove from active list
            pass
            
    # Get Today's Date
    today = datetime.today().strftime('%Y-%m-%d')
    
    # Add list to key value pair where key = today's date 
    data_json = {today: data_list}
    
    # Write to file and Insert into mongodb compass


if __name__ == '__main__':
    main()
# -*- coding: utf-8 -*- Created on Mon Aug 30 10:06:22 2021  @author: jburke # Query string template # Request info from the API ########################################################################################################## # To be replaced with call to MongoDB - User_Id DB ########################################################################################################## # Remove from active list # Get Today's Date # Add list to key value pair where key = today's date # Write to file and Insert into mongodb compass