-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed DB structure for PharmaDoc table to use full pharmacy list
- Loading branch information
Newvick Lee
committed
May 10, 2018
1 parent
a84e964
commit f5b014d
Showing
6 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import csv | ||
import sys | ||
import json | ||
import sqlite3 | ||
|
||
# Usage: | ||
# python import_pharmacies.py /path/to/pharmacies_list.csv | ||
# (from http://www.bcpharmacists.org/list-community-pharmacies) | ||
# /path/to/ineedmy.db (for example ./ineedmy.db) | ||
|
||
if __name__ == '__main__': | ||
tgt_conn = sqlite3.connect(sys.argv[2]) | ||
|
||
with open(sys.argv[1], 'r') as csvfile: | ||
csvreader = csv.reader(csvfile) | ||
next(csvreader) #skip header | ||
for row in csvreader: | ||
name = row[0] | ||
address = row[1].replace('\n', ' ') | ||
manager = row[2] | ||
phone = row[3] | ||
fax = row[4] | ||
|
||
cur = tgt_conn.cursor() | ||
cur.execute('INSERT INTO PharmaDoc (name, address, phone, fax, manager) VALUES(?, ?, ?, ?, ?)', ((name, address, phone, fax, manager))) | ||
|
||
tgt_conn.commit() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import re | ||
import requests | ||
from bs4 import BeautifulSoup | ||
import csv | ||
import time | ||
|
||
|
||
def pharmacy_list(): | ||
|
||
url = "http://www.bcpharmacists.org/list-community-pharmacies" | ||
page = requests.get(url) | ||
soup = BeautifulSoup(page.content, 'html.parser') | ||
|
||
|
||
table = soup.find_all('table')[0] | ||
table_rows = table.find_all('tr') | ||
del table_rows[0] | ||
|
||
with open('pharmacies_list.csv', 'w') as csvfile: | ||
fieldnames = ['name', 'address', 'manager', 'phone', 'fax'] | ||
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | ||
writer.writeheader() | ||
|
||
for index, table_row in enumerate(table_rows, 0): | ||
cells = table_row.findAll('td') | ||
#Finding name | ||
name = cells[0].text.strip() | ||
|
||
#Finding address | ||
address = cells[1].text.strip() | ||
|
||
#Manager | ||
manager = cells[2].text.strip() | ||
|
||
#Phone | ||
raw_phone = cells[3].text.strip() | ||
phone = re.sub("\D", "", raw_phone) | ||
|
||
#Fax | ||
raw_fax = cells[4].text.strip() | ||
fax = re.sub("\D", "", raw_fax) | ||
|
||
writer.writerow({'name': name, 'address': address, 'manager': manager, 'phone': phone, 'fax': fax}) | ||
|
||
|
||
|
||
pharmacy_list() |