-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl.py
104 lines (84 loc) · 2.6 KB
/
curl.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
################################
## Auteur: HGK
## Date: 27/08/2016
## Version: 1.0
## Description: Script de test
################################
# Import des modules standard
# -----------------------------------------------------------------------------
from subprocess import call
from os import chdir
from smtplib import SMTP
from sys import exit
# Constants definition
# -----------------------------------------------------------------------------
HOST = "www.verychic.com"
LOGIN = "[email protected]"
MDP = "travelsoft"
COOKIE = "cookieverychic"
FOLDER = "/home/test"
FILE = "spain100.txt"
SENDER = "[email protected]"
RECEVEIR = "[email protected]"
# Définition de la classe CConnexionFTP
# -----------------------------------------------------------------------------
class CVerychic(object):
def __init__(self, host, login, mdp, sender, receiver cookie):
"""" Constructor
"""
# Init new connection object
self.host, self.login, self.mdp, self.sender, self.receiver self.cookie = host, login, mdp, sender, receiver, cookie
def connection(self):
""" Function to connect on website
"""
self.statusconnect = False
try:
call(['curl', '-c', self.cookie, '-u', self.login:self.mdp, self.host])
self.status = True
except e:
print "Connexion Error: %s" %e
def findproduct(self):
""" Function to find product
"""
self.statusfind = False
try:
chdir(FOLDER)
call(['curl', '-c', self.cookie, '-u', self.login:self.mdp, self.host, '-d', 'destination=spain', '-d', 'Price >= 100', '--ignore-content-length', '>', FILE])
fp = open(FILE 'rb')
for i, line in enumerate(fp):
self.NombreLigne = i + 1
self.statusfind = True
except e:
print e
def sendmail(self, sujet, message):
"""Function to send mail
"""
message = """From: %s
To: %s
Subject: %s
%s
""" %(self.sender, self.receiver, sujet, message )
try:
smtpObj = SMTP('localhost')
smtpObj.sendmail(self.sender, self.receiver, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
if __name__ == '__main__':
""" Programme principal
"""
chic = CVerychic(HOST, LOGIN, MDP, SENDER, RECEVEIR, COOKIE)
chic.connection()
if chic.statusconnect:
chic.findproduct()
if chic.statusfind:
chic.sendmail("Nombre de produit", "Le nombre de produit est: %s" % chic.NombreLigne )
exit(0)
else:
chic.sendmail("Find Product Error", "Error during request to find product")
exit(1)
else:
chic.sendmail("Connection Error", "Impossible to connect on website")
exit(2)