Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'syntax': 0.04; 'elif': 0.05; 'great.': 0.07; 'subject:code': 0.07; 'fname': 0.09; 'skip:g 60': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.11; 'subject:Help': 0.11; 'python': 0.11; 'chris,': 0.16; 'cmd': 0.16; 'time.time()': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'help.': 0.21; 'import': 0.22; 'skip:+ 20': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; '31,': 0.24; 'please?': 0.24; 'mon,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; "we'd": 0.29; 'am,': 0.29; 'important.': 0.30; 'code': 0.31; 'posting': 0.31; 'reply.': 0.31; 'indentation': 0.31; 'could': 0.34; 'subject:with': 0.35; 'received:209.85': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'received:209': 0.37; 'skip:o 20': 0.38; 'days': 0.60; 'march': 0.61; 'first': 0.61; "you'll": 0.62; "you've": 0.63; 'skip:r 30': 0.69; '(sue': 0.84; 'me!': 0.84; 'sue': 0.84; 'expires': 0.91; '2013': 0.98 X-Received: by 10.49.86.40 with SMTP id m8mr628053qez.30.1364763980171; Sun, 31 Mar 2013 14:06:20 -0700 (PDT) Newsgroups: comp.lang.python Date: Sun, 31 Mar 2013 14:06:19 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=99.233.107.10; posting-account=9KhqJwoAAACtxd9fjX3ptGbRoyWSd7VI References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 99.233.107.10 MIME-Version: 1.0 Subject: Re: Help with python code! From: jojo To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364763983 news.xs4all.nl 6871 [2001:888:2000:d::a6]:53206 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42408 On Sunday, March 31, 2013 4:39:11 PM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 7:10 AM, jojo wrote: >=20 > > Im used to C# so the syntax looks bizarre to me! Any help would be grea= t. >=20 >=20 >=20 > The first thing you'll need to understand about Python syntax is that >=20 > indentation is important. By posting this code flush-left, you've >=20 > actually destroyed its block structure. Could you post it again, with >=20 > indentation, please? We'd then be in a much better position to help. >=20 >=20 >=20 > Chris Angelico Hi Chris, thanks for your reply. See code below... import time import glob import re import os current_time =3D time.time() + 60*60+24*30 dirList =3D glob.glob('\content\paytek\ejbProperties\cybersource\*.crt') q =3D re.compile('^Owner:.*CN=3D([^\s\,]+)') p =3D re.compile('until: (\w+) (\w+) (\d+) (\d+):(\d+):(\d+) \w+ (\d+)') cert_name =3D "" days =3D {"Mon":0, "Tue":1, "Wed":2, "Thu":3, "Fri":4, "Sat":5, "Sun":6} months =3D {"Jan":1, "Feb":2, "Mar":3, "Apr":4, "May":5, "Jun":6, "Jul":7, "Aug":8, "Sep":9, "Oct":10, "Nov":11, "Dec":12} for fname in dirList: cmd =3D "keytool =ADprintcert =ADfile " + fname for line in os.popen(cmd).readlines(): line =3D line.rstrip() m =3D p.search(line) if m: sue =3D time.mktime( (int(m.group(7)), int(months[m.group(2)]), int(m.group(3)), int(m.group(4)), int(m.group(5)), int(m.group(6)), int(days[m.group(1)]), 0, 0) ) expire_time =3D (sue =AD current_time)/60/60/24 if expire_time < 0: print cert_name + " has already expired!" elif expire_time < 31: print cert_name + " expires in " +str(int(expire_time)) + " days" else: m =3D q.search(line) if m: cert_name =3D m.group(1)