| 7391 |
rajveer |
1 |
#!/usr/bin/python
|
|
|
2 |
'''
|
|
|
3 |
|
|
|
4 |
@author: Rajveer
|
|
|
5 |
'''
|
|
|
6 |
import sys
|
|
|
7 |
import imaplib
|
|
|
8 |
import email
|
|
|
9 |
from shop2020.model.v1.order.impl import DataAccessors, DataService
|
|
|
10 |
from shop2020.model.v1.order.impl.DataService import Order
|
|
|
11 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
|
|
12 |
|
|
|
13 |
if __name__ == '__main__' and __package__ is None:
|
|
|
14 |
import os
|
|
|
15 |
sys.path.insert(0, os.getcwd())
|
|
|
16 |
|
|
|
17 |
from_user = 'cnc.center@shop2020.in'
|
|
|
18 |
from_pwd = '5h0p2o2o'
|
|
|
19 |
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "parmod.kumar@shop2020.in"]
|
|
|
20 |
|
|
|
21 |
def process_store_price_approval(orderId):
|
|
|
22 |
subject = str(orderId)
|
|
|
23 |
user = 'cnc.center@shop2020.in'
|
|
|
24 |
pwd = '5h0p2o2o'
|
|
|
25 |
|
|
|
26 |
# connecting to the gmail imap server
|
|
|
27 |
m = imaplib.IMAP4_SSL("imap.gmail.com")
|
|
|
28 |
m.login(user,pwd)
|
|
|
29 |
m.select("Inbox", True) # use m.list() to get all the mailboxes
|
|
|
30 |
|
|
|
31 |
# you could filter using the IMAP rules here (check http://www.example-code.com/csharp/imap-search-critera.asp)
|
|
|
32 |
resp, items = m.search(None, 'SUBJECT', subject, 'UNKEYWORD', 'processed')
|
|
|
33 |
items = items[0].split() # getting the mail ids
|
|
|
34 |
|
|
|
35 |
for emailid in reversed(items):
|
|
|
36 |
# fetching the mail, "`(RFC822)`" means "get the whole stuff", but you can ask for headers only, etc
|
|
|
37 |
resp, data = m.fetch(emailid, "(RFC822)")
|
|
|
38 |
email_body = data[0][1] # getting the mail content
|
|
|
39 |
mail = email.message_from_string(email_body) # parsing the mail content to get a mail object
|
|
|
40 |
for part in mail.walk():
|
|
|
41 |
if part.get_content_type() == "multipart/alternative":
|
|
|
42 |
continue
|
|
|
43 |
btext = part.get_payload(decode=1)
|
|
|
44 |
btext = btext.strip()
|
|
|
45 |
if btext.lower().startswith('approved'):
|
|
|
46 |
DataAccessors.verify_order(orderId)
|
|
|
47 |
if btext.lower().startswith('approved'):
|
|
|
48 |
DataAccessors.refund_order(orderId, "Automatically", "Pricing not approved by approving authority")
|
|
|
49 |
|
|
|
50 |
def main():
|
|
|
51 |
DataService.initialize()
|
|
|
52 |
#DataService.initialize('transaction', '192.168.190.114')
|
|
|
53 |
orders = Order.query.filter(Order.status == OrderStatus.COD_VERIFICATION_PENDING).filter(Order.source == 2).all()
|
|
|
54 |
if orders:
|
|
|
55 |
for order in orders:
|
|
|
56 |
process_store_price_approval(order.id)
|
|
|
57 |
|
|
|
58 |
if __name__ == '__main__':
|
|
|
59 |
main()
|