Added created date for new domains
This commit is contained in:
parent
d271c44adf
commit
ebe9ff1860
28
ddns.py
28
ddns.py
@ -19,7 +19,7 @@ filepath = homefilepath.joinpath('.config/ddns')
|
||||
database = filepath.joinpath('ddns.db')
|
||||
logfile = filepath.joinpath('ddns.log')
|
||||
logging.basicConfig(filename=logfile,level=logging.INFO)
|
||||
app_version = '0.4.1'
|
||||
app_version = '0.4.2'
|
||||
|
||||
|
||||
def get_ip():
|
||||
@ -161,7 +161,7 @@ def add_subdomain(domain):
|
||||
if response != 'Fail':
|
||||
response_data = response.json()
|
||||
domainid = str(response_data['domain_record']['id'])
|
||||
cursor.execute('INSERT INTO subdomains values(?,?,?,?,?,?,?)',(domainid,topdomain_id,sub,ip,None,now,now,))
|
||||
cursor.execute('INSERT INTO subdomains values(?,?,?,?,?,?,?)',(domainid,topdomain_id,sub,ip,None,now,now,now,))
|
||||
conn.commit()
|
||||
print('The domain %s has been added.' % (domain))
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M") + ' - Info : subdomain %s added'%(domain))
|
||||
@ -240,7 +240,8 @@ def list_sub_domains(domain):
|
||||
if count == 0:
|
||||
print("[red]Error: [/red]No such domain. Check spelling or use ddns -d to show all top domains.")
|
||||
else:
|
||||
print('\n\nCurrent sub domains for [b]%s[/b]' % (domain))
|
||||
print('\n\nCurrent sub domains for [b]%s[/b]\n\n' % (domain))
|
||||
print('Domain\t\t\t\tCreated\t\t\tUpdated\t\t\tChecked')
|
||||
print('===============================================================================================')
|
||||
cursor.execute('SELECT id FROM domains WHERE name LIKE ?', (domain,))
|
||||
topdomain_id = cursor.fetchone()[0]
|
||||
@ -249,12 +250,12 @@ def list_sub_domains(domain):
|
||||
if count == 0:
|
||||
print('[red]Error:[/red] No sub domains for [b]%s[/b]' % (domain))
|
||||
else:
|
||||
cursor.execute('SELECT name,last_updated,last_checked FROM subdomains WHERE main_id LIKE ?',(topdomain_id,) )
|
||||
cursor.execute('SELECT name,last_updated,last_checked,created FROM subdomains WHERE main_id LIKE ?',(topdomain_id,) )
|
||||
subdomains = cursor.fetchall()
|
||||
for i in subdomains:
|
||||
topdomain = i[0]+'.'+domain
|
||||
topdomain = "{:<25}".format(topdomain)
|
||||
print(topdomain+'\tUpdated : '+i[1]+'\tChecked : '+i[2])
|
||||
print(topdomain+'\t'+i[3]+'\t'+i[1]+'\t'+i[2])
|
||||
print('\n')
|
||||
|
||||
|
||||
@ -455,21 +456,29 @@ def local_add_subdomain(domain,domainid):
|
||||
def updatedb():
|
||||
# Update DB with new column 20.03.23
|
||||
# Add last updated field for subdomains
|
||||
new_table = 'last_updated'
|
||||
new_column = 'last_updated'
|
||||
info = conn.execute("PRAGMA table_info('subdomains')").fetchall()
|
||||
if not any(new_table in word for word in info):
|
||||
if not any(new_column in word for word in info):
|
||||
add_column = "ALTER TABLE subdomains ADD COLUMN last_updated text default 'N/A'"
|
||||
conn.execute(add_column)
|
||||
conn.commit()
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M")+' - Info : Database updated')
|
||||
|
||||
new_table = 'last_checked'
|
||||
new_column = 'last_checked'
|
||||
info = conn.execute("PRAGMA table_info('subdomains')").fetchall()
|
||||
if not any(new_table in word for word in info):
|
||||
if not any(new_column in word for word in info):
|
||||
add_column = "ALTER TABLE subdomains ADD COLUMN last_checked text default 'N/A'"
|
||||
conn.execute(add_column)
|
||||
conn.commit()
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M") + ' - Info : Database updated')
|
||||
|
||||
new_column = 'created'
|
||||
info = conn.execute("PRAGMA table_info('subdomains')").fetchall()
|
||||
if not any(new_column in word for word in info):
|
||||
add_column = "ALTER TABLE subdomains ADD COLUMN created text default '2023-01-01 00:00'"
|
||||
conn.execute(add_column)
|
||||
conn.commit()
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M") + ' - Info : Database updated')
|
||||
|
||||
|
||||
|
||||
@ -548,3 +557,4 @@ elif args['local']:
|
||||
local_add_subdomain(args['local'][0][0],args['local'][0][1])
|
||||
else:
|
||||
updateip(None)
|
||||
|
Loading…
Reference in New Issue
Block a user