I was wondering, whether it is possible to compare two text files(the index stock file created when the program is started and one created every 15 seconds) and trigger an event if the available line is different for a product?
I'm looking forward to your answers : )
import bs4 as bs
import urllib.request
import discord
from discord.ext import commands
from dhooks import Webhook
import requests
import json
import time
from datetime import datetime
linex = 1
liney = 1
r = requests.get("https://www.feature.com/products.json")
products = json.loads((r.text))["products"]
now = datetime.now()
data = ("available")
for product in products:
print("============================================")
print(product["title"])
print(product["tags"])
print(product["published_at"])
print(product["created_at"])
print(product["product_type"])
for variant in product["variants"]:
print(variant['title'])
print(variant['available'],"\n")
data =("available")
with open("stock_index.txt","w") as f:
f.write(str(now)+"\n")
f.write("============================================\n")
f.write("=============STOCK-AVAILABILITY============\n")
f.write("============================================\n\n\n")
for product in products:
for variant in product["variants"]:
if variant['available'] == True:
f.write(product["title"]+"\n")
f.write(variant['title']+"\n")
f.write((str(variant["available"])+("\n")))
f.write("--------------------\n")
file1 = open('stock_index.txt', 'r')
file2 = open('stock_index_hourly-update.txt', 'r')
FO = open('some_output_file.txt', 'w')
for linex in file1:
for liney in file2:
if linex == liney:
FO.write("%s\n" %(linex))
linex +=1
liney +=1
FO.close()
file1.close()
file2.close()