2019-10-26 15:25:21 +00:00
|
|
|
from django.shortcuts import render
|
2019-10-27 15:20:28 +00:00
|
|
|
from selenium import webdriver
|
|
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
from selenium.webdriver.support.ui import Select
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
import random
|
|
|
|
from dbsettings.views import getValue
|
|
|
|
from buyer.models import Card
|
|
|
|
import time
|
2021-02-06 11:42:45 +00:00
|
|
|
from smsauth.views import sendMessage, SELLER
|
2019-10-26 15:25:21 +00:00
|
|
|
|
2019-10-27 15:20:28 +00:00
|
|
|
def getCard(allow_buy=False):
|
|
|
|
unused = Card.objects.filter(delivered=None) # pylint: disable=E1101
|
|
|
|
try:
|
|
|
|
card = random.SystemRandom().choice(unused)
|
|
|
|
except:
|
|
|
|
if allow_buy:
|
|
|
|
card = buyCard()
|
|
|
|
else:
|
|
|
|
card = None
|
|
|
|
return card
|
|
|
|
|
|
|
|
|
|
|
|
def buyCard():
|
|
|
|
browser = webdriver.Firefox()
|
|
|
|
|
|
|
|
browser.get("https://www.wkv.com/?action=my_account")
|
|
|
|
|
|
|
|
if "Login" in browser.title:
|
|
|
|
user = browser.find_element_by_name("email")
|
|
|
|
user.send_keys(getValue("buyer.wkv.email"))
|
|
|
|
pwd = browser.find_element_by_name("password")
|
|
|
|
pwd.send_keys(getValue("buyer.wkv.password") + Keys.RETURN)
|
|
|
|
time.sleep(2)
|
|
|
|
if "Login" in browser.title:
|
|
|
|
raise ValueError("Could not log in. Please check if the provided credentials are correct.")
|
|
|
|
|
|
|
|
browser.get("https://www.wkv.com/?action=buy_card&pr=1&pf=1")
|
|
|
|
|
|
|
|
product = Select(browser.find_element_by_name("product"))
|
|
|
|
product.select_by_visible_text("paysafecard classic 10€")
|
|
|
|
browser.find_element_by_class_name("btn").click()
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
browser.find_element_by_class_name("btn").click()
|
|
|
|
|
|
|
|
method = Select(browser.find_elements_by_name("payment_method"))
|
|
|
|
method.select_by_visible_text("Credit card")
|
|
|
|
browser.find_element_by_class_name("btn").click()
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
browser.find_element_by_name("accept_terms").click()
|
|
|
|
browser.find_element_by_class_name("btn").click()
|
|
|
|
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
try:
|
|
|
|
browser.find_element_by_id("existingCcSelect")
|
|
|
|
except:
|
|
|
|
ccnum = browser.find_element_by_name("pan")
|
|
|
|
ccnum.send_keys(getValue("buyer.creditcard.number"))
|
|
|
|
expmonth = Select(browser.find_element_by_name("newExpMonth"))
|
|
|
|
expmonth.select_by_value(str(int(getValue("buyer.creditcard.expmonth"))))
|
|
|
|
expyear = Select(browser.find_element_by_name("newExpYear"))
|
|
|
|
expyear.select_by_visible_text(getValue("buyer.creditcard.expyear"))
|
|
|
|
finally:
|
|
|
|
cvv = browser.find_element_by_name("cvv")
|
|
|
|
cvv.send_keys(getValue("buyer.creditcard.cvv") + Keys.RETURN)
|
|
|
|
|
|
|
|
time.sleep(15)
|
|
|
|
|
2020-02-01 15:05:10 +00:00
|
|
|
return Card()
|
|
|
|
|
|
|
|
def sendStatus():
|
|
|
|
status = len(Card.objects.filter(delivered=None))
|
2021-02-06 11:42:45 +00:00
|
|
|
return sendMessage("A Paysafecard has been sold. There are %i remaining in stock." % status, SELLER)
|