How can I make my code more pythonic ? I definitely think there is a way to make this code a lot more readable and clear + shorter...
But I haven't found an effective way. Any techniques I can use to make it more concise and clear?
#!/usr/bin/env python
import requests
import socket
import random
import re
import time
link = "https://100.1.X.X/testpage.html"
ipAddresses = ['100.1.177.1', '100.1.177.2', '100.1.177.3']
superprice = 31867
medprice = 22992
gutdop = 12000
targetsuper = ["QHTxDZ7I56KU", "bXH5ApeO4", "tLu8JAllx8zJfA", "LwJ2UUGcVs_ns"]
targetmedium = ["QHTxDZ7I56KU", "bXH5ApeO4", "tLu8JAllx8zJfA", "LwJ2UUGcVs_ns"]
targetknife = ["QHTxDZ7I56KU", "bXH5ApeO4", "tLu8JAllx8zJfA", "LwJ2UUGcVs_ns"]
targetdoppler = ["QHTxDZ7I56KU", "bXH5ApeO4", "tLu8JAllx8zJfA", "LwJ2UUGcVs_ns"]
targetm = ["QHTxDZ7I56KU", "bXH5ApeO4", "tLu8JAllx8zJfA", "LwJ2UUGcVs_ns"]
targetmg = ["QHTxDZ7I56KU", "bXH5ApeO4", "tLu8JAllx8zJfA", "LwJ2UUGcVs_ns"]
def SaleProcess(cart, cookie_value):
print "=========FOUND SOMETHING========="
print cart
print cookie_value
def main():
x = 0
while True:
try:
proc_c = cookie_value
start = Scanner(cookie_value)
except:
print "= Sleeping for 1sec and trying again"
time.sleep(1)
continue
def Scanner(cookie_value):
x = 0
while x < 14400:
for ipAddress in ipAddresses:
#leave clear for now
x = x + 1
try:
#DO request with ipAddress
response = request.get(link)
strResponce = str(response)
regexp = "&item=(.*?)'>(.*?)<"
analystid = re.findall(regexp, strResponce)
regexp = 'addToCart\((.*?)\)'
price = re.findall(regexp, strResponce)
regexp = 'image\/(.*?)\/256fx256f'
image = re.findall(regexp, strResponce)
price1,analystid1,image1 = price[:1],analystid[:1],image[:1]
price2,analystid2,image2 = price[1:2],analystid[1:2],image[1:2]
price3,analystid3,image3 = price[2:3],analystid[2:3],image[2:3]
price4,analystid4,image4 = price[3:4],analystid[3:4],image[3:4]
price5,analystid5,image5 = price[4:5],analystid[4:5],image[4:5]
price6,analystid6,image6 = price[5:6],analystid[5:6],image[5:6]
price7,analystid7,image7 = price[6:7],analystid[6:7],image[6:7]
price8,analystid8,image8 = price[7:8],analystid[7:8],image[7:8]
price9,analystid9,image9 = price[8:9],analystid[8:9],image[8:9]
price10,analystid10,image10 = price[9:10],analystid[9:10],image[9:10]
except:
print "Request issue"
x = x + 14400
break
try:
cart1,analyst1 = str(analystid1).split(",")
cart2,analyst2 = str(analystid2).split(",")
cart3,analyst3 = str(analystid3).split(",")
cart4,analyst4 = str(analystid4).split(",")
cart5,analyst5 = str(analystid5).split(",")
cart6,analyst6 = str(analystid6).split(",")
cart7,analyst7 = str(analystid7).split(",")
cart8,analyst8 = str(analystid8).split(",")
cart9,analyst9 = str(analystid9).split(",")
cart10,analyst10 = str(analystid10).split(",")
analyst1 = analyst1[2:-3]
analyst2 = analyst2[2:-3]
analyst3 = analyst3[2:-3]
analyst4 = analyst4[2:-3]
analyst5 = analyst5[2:-3]
analyst6 = analyst6[2:-3]
analyst7 = analyst7[2:-3]
analyst8 = analyst8[2:-3]
analyst9 = analyst9[2:-3]
analyst10 = analyst10[2:-3]
cart1 = cart1[3:-1]
cart2 = cart2[3:-1]
cart3 = cart3[3:-1]
cart4 = cart4[3:-1]
cart5 = cart5[3:-1]
cart6 = cart6[3:-1]
cart7 = cart7[3:-1]
cart8 = cart8[3:-1]
cart9 = cart9[3:-1]
cart10 = cart10[3:-1]
price1 = str(price1)
price2 = str(price2)
price3 = str(price3)
price4 = str(price4)
price5 = str(price5)
price6 = str(price6)
price7 = str(price7)
price8 = str(price8)
price9 = str(price9)
price10 = str(price10)
price1 = price1.strip("[]").replace('\'', '')
price2 = price2.strip("[]").replace('\'', '')
price3 = price3.strip("[]").replace('\'', '')
price4 = price4.strip("[]").replace('\'', '')
price5 = price5.strip("[]").replace('\'', '')
price6 = price6.strip("[]").replace('\'', '')
price7 = price7.strip("[]").replace('\'', '')
price8 = price8.strip("[]").replace('\'', '')
price9 = price9.strip("[]").replace('\'', '')
price10 = price10.strip("[]").replace('\'', '')
(cartid1, tprice1) = price1.split(",")
(cartid2, tprice2) = price2.split(",")
(cartid3, tprice3) = price3.split(",")
(cartid4, tprice4) = price4.split(",")
(cartid5, tprice5) = price5.split(",")
(cartid6, tprice6) = price6.split(",")
(cartid7, tprice7) = price7.split(",")
(cartid8, tprice8) = price8.split(",")
(cartid9, tprice9) = price9.split(",")
(cartid10, tprice10) = price10.split(",")
cartid1 = str(cartid1)
cartid2 = str(cartid2)
cartid3 = str(cartid3)
cartid4 = str(cartid4)
cartid5 = str(cartid5)
cartid6 = str(cartid6)
cartid7 = str(cartid7)
cartid8 = str(cartid8)
cartid9 = str(cartid9)
cartid10 = str(cartid10)
totalprice1 = float(tprice1)
totalprice2 = float(tprice2)
totalprice3 = float(tprice3)
totalprice4 = float(tprice4)
totalprice5 = float(tprice5)
totalprice6 = float(tprice6)
totalprice7 = float(tprice7)
totalprice8 = float(tprice8)
totalprice9 = float(tprice9)
totalprice10 = float(tprice10)
image1 = str(image1)[2:-3]
image2 = str(image2)[2:-3]
image3 = str(image3)[2:-3]
image4 = str(image4)[2:-3]
image5 = str(image5)[2:-3]
image6 = str(image6)[2:-3]
image7 = str(image7)[2:-3]
image8 = str(image8)[2:-3]
image9 = str(image9)[2:-3]
image10 = str(image10)[2:-3]
except:
print "Resetting counter"
x = x + 14400
break
print "==============================="
print analyst1,totalprice1
print analyst2,totalprice2
print analyst3,totalprice3
print analyst4,totalprice4
print analyst5,totalprice5
print analyst6,totalprice6
print analyst7,totalprice7
print analyst8,totalprice8
print analyst9,totalprice9
print analyst10,totalprice10
#if totalprice1 <= 10:
# if cart1 == cartid1:
# cart = cart1
# JustDOit = SaleProcess(cart, cookie_value)
if any(text in analyst1 for text in targetknife):
if totalprice1 <= 3000:
if cart1 == cartid1:
cart = cart1
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst1 for word in targetdoppler):
if image1 in targetmg:
if totalprice1 <= superprice:
if cart1 == cartid1:
cart = cart1
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice1 <= gutdop:
if cart1 == cartid1:
cart = cart1
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst1 for string in targetsuper):
if totalprice1 <= superprice:
if cart1 == cartid1:
cart = cart1
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst1 for string in targetmedium):
if totalprice1 <= medprice:
if cart1 == cartid1:
cart = cart1
JuststDOit = SaleProcess(cart, cookie_value)
#number2
if any(text in analyst2 for text in targetknife):
if totalprice2 <= 3000:
if cart2 == cartid2:
cart = cart2
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst2 for word in targetdoppler):
if image2 in targetmg:
if totalprice2 <= superprice:
if cart2 == cartid2:
cart = cart2
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice2 <= gutdop:
if cart2 == cartid2:
cart = cart2
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst2 for string in targetsuper):
if totalprice2 <= superprice:
if cart2 == cartid2:
cart = cart2
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst2 for string in targetmedium):
if totalprice2 <= medprice:
if cart2 == cartid2:
cart = cart2
JustDOit = SaleProcess(cart, cookie_value)
#number3
if any(text in analyst3 for text in targetknife):
if totalprice3 <= 3000:
if cart3 == cartid3:
cart = cart3
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst3 for word in targetdoppler):
if image3 in targetmg:
if totalprice3 <= superprice:
if cart3 == cartid3:
cart = cart3
JustDOit = SaleProcess(cart, cookie_value)
if image3 in targetm:
if totalprice3 <= gutdop:
if cart3 == cartid3:
cart = cart3
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst3 for string in targetsuper):
if totalprice3 <= superprice:
if cart3 == cartid3:
cart = cart3
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst3 for string in targetmedium):
if totalprice3 <= medprice:
if cart3 == cartid3:
cart = cart3
JustDOit = SaleProcess(cart, cookie_value)
#number4
if any(text in analyst4 for text in targetknife):
if totalprice4 <= 3000:
if cart4 == cartid4:
cart = cart4
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst4 for word in targetdoppler):
if image4 in targetmg:
if totalprice4 <= superprice:
if cart4 == cartid4:
cart = cart4
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice4 <= gutdop:
if cart4 == cartid4:
cart = cart4
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst4 for string in targetsuper):
if totalprice4 <= superprice:
if cart4 == cartid4:
cart = cart4
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst4 for string in targetmedium):
if totalprice4 <= medprice:
if cart4 == cartid4:
cart = cart4
JustDOit = SaleProcess(cart, cookie_value)
#number5
if any(text in analyst5 for text in targetknife):
if totalprice5 <= 3000:
if cart5 == cartid5:
cart = cart5
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst5 for word in targetdoppler):
if image5 in targetmg:
if totalprice5 <= superprice:
if cart5 == cartid5:
cart = cart5
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice5 <= gutdop:
if cart5 == cartid5:
cart = cart5
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst5 for string in targetsuper):
if totalprice5 <= superprice:
if cart5 == cartid5:
cart = cart5
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst5 for string in targetmedium):
if totalprice5 <= medprice:
if cart5 == cartid5:
cart = cart5
JustDOit = SaleProcess(cart, cookie_value)
#number6
if any(text in analyst6 for text in targetknife):
if totalprice6 <= 3000:
if cart6 == cartid6:
cart = cart6
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst6 for word in targetdoppler):
if image6 in targetmg:
if totalprice6 <= superprice:
if cart6 == cartid6:
cart = cart6
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice6 <= gutdop:
if cart6 == cartid6:
cart = cart6
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst6 for string in targetsuper):
if totalprice6 <= superprice:
if cart6 == cartid6:
cart = cart6
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst6 for string in targetmedium):
if totalprice6 <= medprice:
if cart6 == cartid6:
cart = cart6
JustDOit = SaleProcess(cart, cookie_value)
#number7
if any(text in analyst7 for text in targetknife):
if totalprice7 <= 3000:
if cart7 == cartid7:
cart = cart7
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst7 for word in targetdoppler):
if image7 in targetmg:
if totalprice7 <= superprice:
if cart7 == cartid7:
cart = cart7
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice7 <= gutdop:
if cart7 == cartid7:
cart = cart7
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst7 for string in targetsuper):
if totalprice7 <= superprice:
if cart7 == cartid7:
cart = cart7
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst7 for string in targetmedium):
if totalprice7 <= medprice:
if cart7 == cartid1:
cart = cart7
JustDOit = SaleProcess(cart, cookie_value)
#number8
if any(text in analyst8 for text in targetknife):
if totalprice8 <= 3000:
if cart8 == cartid8:
cart = cart8
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst8 for word in targetdoppler):
if image8 in targetmg:
if totalprice8 <= superprice:
if cart8 == cartid8:
cart = cart8
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice8 <= gutdop:
if cart8 == cartid8:
cart = cart8
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst8 for string in targetsuper):
if totalprice8 <= superprice:
if cart8 == cartid8:
cart = cart8
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst8 for string in targetmedium):
if totalprice8 <= medprice:
if cart8 == cartid8:
cart = cart8
JustDOit = SaleProcess(cart, cookie_value)
#number9
if any(text in analyst9 for text in targetknife):
if totalprice9 <= 3000:
if cart9 == cartid9:
cart = cart9
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst9 for word in targetdoppler):
if image9 in targetmg:
if totalprice9 <= superprice:
if cart9 == cartid9:
cart = cart9
JustDOit = SaleProcess(cart, cookie_value)
if image9 in targetm:
if totalprice9 <= gutdop:
if cart9 == cartid9:
cart = cart9
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst9 for string in targetsuper):
if totalprice9 <= superprice:
if cart9 == cartid9:
cart = cart9
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst9 for string in targetmedium):
if totalprice9 <= medprice:
if cart9 == cartid9:
cart = cart9
JustDOit = SaleProcess(cart, cookie_value)
#number10
if any(text in analyst10 for text in targetknife):
if totalprice10 <= 3000:
if cart10 == cartid10:
cart = cart10
JustDOit = SaleProcess(cart, cookie_value)
if any(word in analyst10 for word in targetdoppler):
if image10 in targetmg:
if totalprice10 <= superprice:
if cart10 == cartid10:
cart = cart10
JustDOit = SaleProcess(cart, cookie_value)
if image1 in targetm:
if totalprice10 <= gutdop:
if cart10 == cartid10:
cart = cart10
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst10 for string in targetsuper):
if totalprice10 <= superprice:
if cart10 == cartid10:
cart = cart10
JustDOit = SaleProcess(cart, cookie_value)
if any(string in analyst10 for string in targetmedium):
if totalprice10 <= medprice:
if cart10 == cartid10:
cart = cart10
JustDOit = SaleProcess(cart, cookie_value)
time.sleep(5)
if __name__ == "__main__":
main()