Added auto-create config
This commit is contained in:
		
							parent
							
								
									71b2927dc1
								
							
						
					
					
						commit
						41cf58cc9a
					
				
							
								
								
									
										29
									
								
								script.py
								
								
								
								
							
							
						
						
									
										29
									
								
								script.py
								
								
								
								
							| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
import time
 | 
			
		||||
import os
 | 
			
		||||
import json
 | 
			
		||||
import pymongo
 | 
			
		||||
import requests
 | 
			
		||||
| 
						 | 
				
			
			@ -16,6 +17,34 @@ print(" |_____/|_| \_|\_____|")
 | 
			
		|||
# Load config
 | 
			
		||||
print("Loading config...")
 | 
			
		||||
 | 
			
		||||
if os.path.exists('config.json') == False:
 | 
			
		||||
    print("Config file not found, Creating...")
 | 
			
		||||
    config = {
 | 
			
		||||
        "mongo" : {
 | 
			
		||||
            "host" : "localhost",
 | 
			
		||||
            "port" : 27017,
 | 
			
		||||
            "db" : "notoric-snc"
 | 
			
		||||
        },
 | 
			
		||||
        "groq" : {
 | 
			
		||||
            "api_key" : ""
 | 
			
		||||
        },
 | 
			
		||||
        "weather" : {
 | 
			
		||||
            "api_key" : "",
 | 
			
		||||
            "city" : "london,uk"
 | 
			
		||||
        },
 | 
			
		||||
        "news" : {
 | 
			
		||||
            "api_key" : "",
 | 
			
		||||
            "country" : "gb",
 | 
			
		||||
            "article_lifetime": 6,
 | 
			
		||||
            "article_interval": 1
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    with open('config.json', 'w') as f:
 | 
			
		||||
        json.dump(config, f)
 | 
			
		||||
    print("Config file created! Please fill in the details in config.json before running the script again.")
 | 
			
		||||
    exit()
 | 
			
		||||
 | 
			
		||||
with open('config.json') as f:
 | 
			
		||||
    config = json.load(f)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue