import requests
import re
import time
from threading import Thread
from bs4 import BeautifulSoup
# {
# "nft_name": {
# "image": "image_url",
# "description": "description",
# "links": {
# "twitter": "twitter_link",
# "discord": "discord_link",
# "instagram": "instagram_link"
# },
# "public_price": "$$$",
# "amnt": "amount_of_nfts",
# "presale_date": "date",
# "network": "crypto_network"
# }
# }
class Session:
def __init__(self):
self.url = "https://www.nftdropscalendar.com"
self.timer = 30 # in minutes
# def write(self, data)
def start(self):
while True:
time.sleep(self.timer * 60)
links = self.retrieve_links()
if links != cached:
for x in links:
if x not in cached:
self.retrieve_info(x)
else:
cached = links
def retrieve_info(self, drop):
soup = BeautifulSoup(requests.get(drop).content, 'html5lib')
links = [link.get("href") for link in soup.find_all("a", class_ = "div-next-drops-info collection nftinfocard w-inline-block")]
links.append(soup.find("a", class_= "link-block-6 w-inline-block").get("href"))
data = {
"nft_name": {
"image": soup.find("img", class_ = "nft-image nextdropimage nftinfocard pg")['src'],
"description": soup.find("p", class_= "nft-description nftinfocard nftinfopage").getText(),
"links": {
"twitter": f"{[x for x in links if 'twitter' in x][0]}",
"discord": f"{[x for x in links if 'discord' in x][0]}",
"site": f"{[x for x in links if 'twitter' not in x and 'discord' not in x][0]}"
},
"public_price": "$$$",
"amnt": "amount_of_nfts",
"presale_date": "date",
"network": "crypto_network"
}
}
# print(data)
print(data)
def retrieve_links(self):
return list(set([self.url + link.get('href') for link in list(BeautifulSoup(requests.get(self.url + "/upcoming-nfts/").content, 'html5lib').find_all('a')) if "/nft-drops/" in link.get('href')]))
def main():
global cached
session = Session()
session.retrieve_info("https://www.nftdropscalendar.com/nft-drops/real-even-shiny-gem")
# session.scrape_all()
# projects = BeautifulSoup(requests.get("https://www.nftdropscalendar.com/upcoming-nfts").content, 'html5lib').find_all('a')
if __name__ == "__main__":
main()