Skip to content

Commit

Permalink
Merge branch 'main' of github.com:gabeklavans/you-got-listings-aggreg…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
ggriffey committed Mar 1, 2024
2 parents 85b102c + 51f27ed commit 26a10bd
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DOMAIN=
IP=
TG_KEY=
CHAT_ID=
AUTH_USER=
Expand Down
1 change: 0 additions & 1 deletion data/listings-example.json

This file was deleted.

1 change: 1 addition & 0 deletions listings-example.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions public/script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
let propertiesObject = {};
let propertiesDiv = document.getElementsByClassName("properties");

fetch("https://ygl.dabe.tech/sites")
fetch("./data/sites.json")
.then((response) => response.json())
.then((sites) => {
fetch("https://ygl.dabe.tech/listings")
fetch("./data/listings.json")
.then((response) => response.json())
.then((json) => {
propertiesObject = json;
.then((propertiesObject) => {
// console.log(propertiesObject);
let i = 0;

Expand Down
5 changes: 3 additions & 2 deletions scraper/bot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import asyncio
import logging
from dotenv import load_dotenv
import os

import telegram
from dotenv import load_dotenv

load_dotenv()

Expand Down
20 changes: 14 additions & 6 deletions scraper/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env python3

import json
import argparse
import json
import shutil
import time
from typing import Dict
from dotenv import load_dotenv

import requests
from bs4 import BeautifulSoup
from dotenv import load_dotenv

import bot

load_dotenv()
Expand Down Expand Up @@ -49,9 +52,13 @@ def fill_properties(old_listings: Dict, new_listings: Dict, ygl_url_base: str):
"notes": "Evil, diabolical, lemon-scented",
"isFavorite": True,
"isDismissed": False,
"timestamp": 888888888,
}
}
'''

timestamp = time.time_ns()

for listing in ygl_listings(f'{ygl_url_base}?beds_from=4&beds_to=5&rent_to=5200&date_from=08%2F02%2F2024'):
listing_element = listing.find('a', class_='item_title')
listing_addr = listing_element.get_text()
Expand Down Expand Up @@ -85,6 +92,7 @@ def fill_properties(old_listings: Dict, new_listings: Dict, ygl_url_base: str):
new_listing['notes'] = ''
new_listing['isFavorite'] = False
new_listing['isDismissed'] = False
new_listing['timestamp'] = timestamp

new_listings[listing_addr] = new_listing

Expand All @@ -94,16 +102,16 @@ def fill_properties(old_listings: Dict, new_listings: Dict, ygl_url_base: str):


if __name__ == "__main__":
with open('../data/sites.json', 'r', encoding='utf-8') as sites_fp:
with open('../public/data/sites.json', 'r', encoding='utf-8') as sites_fp:
sites = json.load(sites_fp)

try:
shutil.copyfile('../data/listings.json', '../data/listings.bak.json')
shutil.copyfile('../public/data/listings.json', '../public/data/listings.bak.json')
except FileNotFoundError as e:
pass

try:
with open('../data/listings.json', 'r', encoding='utf-8') as listings_fp:
with open('../public/data/listings.json', 'r', encoding='utf-8') as listings_fp:
old_listings = json.load(listings_fp)
except IOError as e:
old_listings = {}
Expand All @@ -112,5 +120,5 @@ def fill_properties(old_listings: Dict, new_listings: Dict, ygl_url_base: str):
for site in sites.keys():
fill_properties(old_listings, new_listings, site)

with open('../data/listings.json', 'w', encoding='utf-8') as listings_file:
with open('../public/data/listings.json', 'w', encoding='utf-8') as listings_file:
json.dump(new_listings, listings_file)
File renamed without changes.
6 changes: 5 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -74,6 +75,9 @@ func main() {
router.GET("/ping", basicAuth, ping)
router.GET("/listings", getListings)
router.GET("/sites", getSites)
router.Static("/static", "../public/")

router.Run("192.168.88.22:8083")
domain := os.Getenv("DOMAIN")
ip := os.Getenv("IP")
router.Run(fmt.Sprintf("%s:%s", domain, ip))
}

0 comments on commit 26a10bd

Please sign in to comment.