-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (38 loc) · 1.63 KB
/
main.py
File metadata and controls
47 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
from bs4 import BeautifulSoup
import pandas as pd
import gspread
from google.oauth2.service_account import Credentials
from datetime import datetime
# Function to scrape Cashify prices
def scrape_cashify_price(device_name):
# url = f"https://www.cashify.in/buy-refurbished-mobile-phones/renewed-{device_name.replace(' ', '-').lower()}"
url="https://www.cashify.in/buy-refurbished-mobile-phones/renewed-apple-iphone-xs/sale/95837"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# Example selector for getting price (modify as per actual structure)
price_tag = soup.find('span', {'class': 'h1'}) # Replace with actual class
if price_tag:
return price_tag.text.strip()
else:
return "Price Not Found"
# Function to update Google Sheet
def update_google_sheet(data):
scope = ["https://www.googleapis.com/auth/spreadsheets"]
creds = Credentials.from_service_account_file('credentials.json')
scoped_creds = creds.with_scopes(scope) # Apply scopes to credentials
client = gspread.authorize(scoped_creds)
sheet_id = "1miZbmJsK9GZHXvwQvn7E0vr9XcRNtKURy7Y-Xw-fxMM"
sheet = client.open_by_key(sheet_id).sheet1
sheet.append_row(data)
# Main function
def main():
device_name = "apple iphone x" # Replace with your device
price = scrape_cashify_price(device_name)
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Prepare data for Google Sheets
data = [date, device_name, price]
# Update Google Sheet
update_google_sheet(data) # Replace with your Google Sheet name
if __name__ == "__main__":
main()