SHARE
TWEET

Untitled

a guest Nov 16th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sqlite3
  2. from sqlite3 import Error
  3. from file_read_backwards import FileReadBackwards
  4.  
  5. def sql_connection():
  6.  
  7.     try:
  8.  
  9.         con = sqlite3.connect('calldata.db')
  10.  
  11.         return con
  12.  
  13.     except Error:
  14.  
  15.         print(Error)
  16.  
  17. def sql_table(con):
  18.  
  19.     cursorObj = con.cursor()
  20.  
  21.     cursorObj.execute("CREATE TABLE hams(callsign text PRIMARY KEY, lastname text, firstname text, MI text, staddress text, city text, state text, zip text, granted text, expires text)")
  22.  
  23.     con.commit()
  24.    
  25. def insert_ham(ham_info):
  26.    
  27.     cursorObj = con.cursor()
  28.    
  29.     cursorObj.execute("INSERT INTO hams(callsign, lastname, firstname, MI, staddress, city, state, zip) VALUES(?, ?, ?, ?, ?, ?, ?, ?)", ham_info)
  30.    
  31.     con.commit()
  32.    
  33. def importFCCdata():
  34.    
  35.     with FileReadBackwards("EN.dat",encoding="utf-8") as in_file, open("calldata.txt", 'w') as out_file:
  36.         callsign_set = set()
  37.         for line in in_file:
  38.             line_list = line.split('|')
  39.             if line_list[4] in callsign_set:
  40.                 continue
  41.             else:
  42.                 callsign_set.add(line_list[4])
  43.                 ham_info = (line_list[4], line_list[10], line_list[8], line_list[9], line_list[15], line_list[16], line_list[17], line_list[18])
  44.                 insert_ham(ham_info)
  45.  
  46. con = sql_connection()
  47.  
  48. sql_table(con)
  49.  
  50. importFCCdata()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top