Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/__pycache__
*.pkl
venv/
API_KEY.py
*.db
*.ipynb_checkpoints
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
repos:
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
# avoid manual add of files once black modifies them
# pre-commit will fail if black has modified the file
# this command will re-add all staged files once black has formatted them
#- entry: bash -c 'black "$@"; echo $(git diff --name-only --staged) | xargs git add' --



- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
# - language_version: python3.10
# - verbose: true
# # avoid manual add of files once isort modifies them
# # pre-commit will fail if isort has modified the file
# # this command will re-add all staged files once isort has formatted them
# - entry: bash -c 'isort "$@"; echo $(git diff --name-only --staged) | xargs git add' --
#
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
hooks:
- id: autoflake
#
9 changes: 5 additions & 4 deletions calculator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.

from dash import Dash, html, dcc, dash_table, callback
from dash.dependencies import Input, Output
from payments import Mortgage
from pages.rentvest import layout as rentvest_layout
import dash
import pandas as pd
from dash import Dash, callback, dash_table, dcc, html
from dash.dependencies import Input, Output

from pages.rentvest import layout as rentvest_layout
from payments import Mortgage

app = Dash(
__name__,
Expand Down
83 changes: 76 additions & 7 deletions house_prices.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import argparse
import pickle as pkl
import sqlite3
import sys

import requests
from bs4 import BeautifulSoup
import sys
import sqlite3
import pickle as pkl
import argparse

from API_KEY import API_KEY
import time

URL_ADD = "https://api.domain.com.au/v1/addressLocators?searchLevel=Suburb&suburb={}&state=NSW&postcode={}"
URL_PERF = "https://api.domain.com.au/v2/suburbPerformanceStatistics/{}/{}/{}?propertyCategory={}&bedrooms={}&periodSize={}&startingPeriodRelativeToCurrent={}&totalPeriods={}"
URL_DEM = "https://api.domain.com.au/v2/demographics/{}/{}/{}?types=AgeGroupOfPopulation%2CCountryOfBirth%2CNatureOfOccupancy%2COccupation%2CGeographicalPopulation%2CGeographicalPopulation%2CEducationAttendance%2CHousingLoanRepayment%2CMaritalStatus%2CReligion%2CTransportToWork%2CFamilyComposition%2CHouseholdIncome%2CRent%2CLabourForceStatus&year={}"
state_map = {"Sydney": "NSW", "Melbourne": "VIC"}
state_map = {"Sydney": "NSW", "Melbourne": "VIC", "Perth": "WA", "Brisbane": "QLD"}

# TODO -> Convert to ORM models


def get_suburbs(city):
Expand Down Expand Up @@ -58,6 +61,72 @@ def get_suburbs(city):
print("No postcode data for {}".format(sub))
continue
return MelSubs
elif city == "Perth":
URL = "https://www.homely.com.au/find-suburb-by-region/perth-greater-western-australia"
HTML = requests.get(URL)
if not HTML.status_code == 200:
sys.exit(URL + " is not available\n", "RESPONSE " + HTML.status_code)
soup = BeautifulSoup(HTML.text, "html.parser")
# allList = soup.find("div", "col-group")
links = soup.find_all("a")
Psubs = []
for link in links:
Psubs.append(link.get_text())
URL = "http://www.justweb.com.au/post-code/perth-postalcodes.html"
HTML = requests.get(URL)
if not HTML.status_code == 200:
sys.exit(URL + " is not available\n", "RESPONSE " + HTML.status_code)
soup = BeautifulSoup(HTML.text, "html.parser")
allList = soup.find_all("select")
subDict = {}
for entry in allList[1].find_all("option"):
txt = entry.get_text()
code = txt[-4:]
sub = txt[:-4].strip()
subDict[sub] = code
PerthSubs = []
for sub in Psubs:
try:
PerthSubs.append((sub, subDict[sub]))
except:
print("No postcode data for {}".format(sub))
continue

return PerthSubs

elif city == "Brisbane":
URL = "https://www.homely.com.au/find-suburb-by-region/brisbane-queensland"
HTML = requests.get(URL)
if not HTML.status_code == 200:
sys.exit(URL + " is not available\n", "RESPONSE " + HTML.status_code)
soup = BeautifulSoup(HTML.text, "html.parser")
# allList = soup.find("div", "col-group")
links = soup.find_all("a")
Bsubs = []
for link in links:
Bsubs.append(link.get_text())
URL = "http://www.justweb.com.au/post-code/brisbane-postalcodes.html"
HTML = requests.get(URL)
if not HTML.status_code == 200:
sys.exit(URL + " is not available\n", "RESPONSE " + HTML.status_code)
soup = BeautifulSoup(HTML.text, "html.parser")
allList = soup.find_all("select")
subDict = {}
for entry in allList[1].find_all("option"):
txt = entry.get_text()
code = txt[-4:]
sub = txt[:-4].strip()
subDict[sub] = code
BrisSubs = []
for sub in Bsubs:
try:
BrisSubs.append((sub, subDict[sub]))
except:
print("No postcode data for {}".format(sub))
continue

return BrisSubs

else:
sys.exit("No implementation for {}".format(city))

Expand Down Expand Up @@ -128,7 +197,7 @@ def create_table_performance(name):
sql.execute(query)


def create_table_demographic(name):
def create_table_demographic(names):
query = """DROP TABLE IF EXISTS {};""".format(name)
sql.execute(query)
query = """CREATE TABLE {} (
Expand Down
Binary file modified housing.db
Binary file not shown.
Binary file removed pages/__pycache__/rentvest.cpython-310.pyc
Binary file not shown.
35 changes: 27 additions & 8 deletions pages/rentvest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from dash import Dash, html, dcc, dash_table, callback
from dash.dependencies import Input, Output
from payments import Mortgage
import dash
import pandas as pd
from dash import Dash, callback, dash_table, dcc, html
from dash.dependencies import Input, Output

from payments import Mortgage

layout = html.Div(
[
Expand Down Expand Up @@ -94,6 +94,18 @@
style={"width": "15%", "margin": "1px"},
inline=False,
),
html.Label(
"Reinvest positive cash flow?",
style={"padding": "10px", "font-weight": "bold", "width": "15%"},
),
dcc.RadioItems(
options=["Yes", "No"],
value="Yes",
id="reinvest-rentvest",
className="form-control-sm",
style={"width": "15%", "margin": "1px"},
inline=False,
),
],
style={
"padding": 10,
Expand Down Expand Up @@ -171,7 +183,7 @@
className="form-control-sm",
style={"width": "15%"},
),
html.Label(
html.Label(
"Personal Rent",
style={"padding": "10px", "font-weight": "bold", "width": "15%"},
),
Expand All @@ -182,7 +194,6 @@
className="form-control-sm",
style={"width": "15%"},
),

],
style={
"padding": 10,
Expand Down Expand Up @@ -222,7 +233,7 @@
Input("rent-rentvest", "value"),
Input("monthly-cost-rentvest", "value"),
Input("personal-rent-rentvest", "value"),

Input("reinvest-rentvest", "value"),
)
def update_graph(
price,
Expand All @@ -236,11 +247,19 @@ def update_graph(
inflation,
rent,
monthly_cost,
personal_rent
personal_rent,
reinvest,
):
m = Mortgage(interest, term, price, deposit, other)
out = m.pl_report_rentvest(
years_hold, growth, inflation, monthly_cost, interest_only, rent, personal_rent
years_hold,
growth,
inflation,
monthly_cost,
interest_only,
rent,
personal_rent,
reinvest,
)
out = [o.strip() for o in out if len(o.strip()) > 0]
# elems = [html.Ul(o) for o in out if len(o)>0 ]
Expand Down
Loading