Skip to content

Commit b943908

Browse files
committed
expiry time added to data
1 parent 4bac05b commit b943908

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Link-Preview/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A script to provide the user with a preview of the link entered.
55
- When entered a link, the script will provide with title, description, and link of the website that the URL points to.
66
- The script will do so by fetching the Html file for the link and analyzing the data from there.
77
- The data will be saved in a `JSON` file named `db.json` for further reference
8-
- Every entry will have a time limit after which it will be updated
8+
- Every entry will have a time limit after which it will be updated (*Data expires after 7 days*)
99

1010
## Setup instructions
1111

Link-Preview/linkPreview.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
import json
33
import os
4+
import time
45
from bs4 import BeautifulSoup
56

67
# to scrape title
@@ -113,7 +114,7 @@ def printData(data):
113114
db = json.loads(data)
114115

115116
# check if it exists
116-
if (url in db):
117+
if (url in db and db[url]["time"] < round(time.time())):
117118
printData(db[url])
118119
else:
119120
# if not in db get via request
@@ -122,12 +123,14 @@ def printData(data):
122123
r = requests.get(url)
123124
soup = BeautifulSoup(r.text, "html.parser")
124125

126+
sevenDaysInSec = 7*24*60*60
125127
# printing data
126128
newData = {
127129
"title": getTitle(soup),
128130
"description": getDesc(soup),
129131
"url": url,
130-
"image": getImage(soup, url)
132+
"image": getImage(soup, url),
133+
"time": round(time.time() * 1000) + sevenDaysInSec
131134
}
132135
printData(newData)
133136
# parse file

0 commit comments

Comments
 (0)