🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.privacy.anon-server
Article #203829

Re: pymenu - panta gateway added

#203829
From: Zax
Date: Sun, 02 Apr 2006 20:38
114 lines
4976 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Sun, 02 Apr 2006 16:11:21 -0400, admin wrote in
Message-Id: <pan.2006.04.02.20.11.19.208879@eelbash.org>:

> Thanks.

Here's an example Python routine for doing date news.group-yyyymmdd
checking.  It will probably wrap horribly but it should give you a few
ideas.


#!/usr/bin/python
#   
# vim: tabstop=4 expandtab shiftwidth=4 autoindent
#
# m2n.py -- This is a template for a date checking mail2news routine where
# newsgroup and date are supplied in a format of news.group-yyyymmdd
#
# Copyright (C) 2005 Steve Crook <steve@mixmin.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.

import sys
import datetime
import re

# Flexibility in allowable timestamps.  These defaults allow for global timezones.
hours_flex = { 'hours_before' : 24,
               'hours_after' : 14 }

# This routine returns True if the date component of the arguement is within scope.
def timecheck(date_params):
    beforetime = datetime.datetime.utcnow() - datetime.timedelta(hours=date_params['hours_before'])
    aftertime = datetime.datetime.utcnow() + datetime.timedelta(hours=date_params['hours_after'])
    now = date_params['stamp']
    year = int(now[0:4])
    month = int(now[4:6])
    day = int(now[6:8])
    
    # If the date component of the supplied arg is a valid date, then
    # pass it on to check if it falls within bounds.
    try:
        nowtime = datetime.datetime(year,month,day)
    except:
        return False

    # By this point, the supplied date arg must be valid, but does
    # it fall within acceptable bounds?
    if nowtime > beforetime and nowtime < aftertime:
        return True
    else:
        return False

# This routine just checks if a single arguement has been passed to the program.
def getargv(args):
    if len(args) == 2:
        return args[1]
    else:
        return 0

# This regex matches a correctly formatted address and extracts the newsgroup
# and the date.  It looks nasty but it works pretty well due to greed.
arg_re = re.compile('(.*\..*)\-([0-9]{8})')

# First, lets check and see if we've been passed one, and only one arguement.
arg = getargv(sys.argv)
if arg:

    # Check if the passed arguement is in the correct format
    arg_format = arg_re.match(arg)
    if arg_format:

        # Extract the newsgroups from the passed arguement
        newsgroup = arg_format.group(1)

        # Extract the date from the passed arguement
        hours_flex['stamp'] = arg_format.group(2)

        # Verify that the date is within defined boundaries
        if timecheck(hours_flex):
            print newsgroup
        else:
            print "Invalid timestamp"

    else:
        print "Incorrect format"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iQEVAwUBRDA2Q2oLu9HNUqmMAQqP2Af/cOlkFHx2atOvakwgsvyvcejTubZAGgCr
Dk712/I6vJv9WizL/K8uzixMTj6Ly4Y8352kqE0V/QbGi4DRTFX7yGj56ld4yC55
rktmQ2d5+3lmciZrrbsx24zXJnFqB2cSFDakmbyoKV5kz1/UGGKJPMv1seD3oNLZ
dEAdMjBGtRaZl7xwOKsqu3JtBH/2Fa1Ka1UgBrSA489tQ/IIEwSWoGzTQUJ5H5bR
QSEEBdnV3Zll1IqxjRS7oXKuU+GPYLKe3WDYhS5aSAMCAmPbsmZfVXOQFB7efT63
jpW6DJ6xdvjTqn5Cn02OzIk/HIygydLFrY+DJI4zA9EX976S4AIL+A==
=GfUH
-----END PGP SIGNATURE-----

-- 
pub  1024D/8ED57743 2003-07-08 Bananasplit Operator
     Key fingerprint = 796F 67E0 E890 A0BB BDAE  EBB4 94A6 7A09 8ED5 7743
uid                            Admin <admin.bananasplit.info>
Technical Details
Message-ID: <e0pco3$2qg$1@bananasplit.info>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!news2.arglkargh.de!news.bananasplit.info!not-for-mail
References: <pan.2006.04.02.17.54.40.77007@eelbash.org> <D3AJK6WK38809.8851388889@anonymous.poster> <pan.2006.04.02.19.46.26.809359@eelbash.org> <e0parj$1ga$1@bananasplit.info> <pan.2006.04.02.20.11.19.208879@eelbash.org>

Show Full Headers
Complete Article Headers
Message-ID: <e0pco3$2qg$1@bananasplit.info>
Subject: Re: pymenu - panta gateway added
Date: Sun, 02 Apr 2006 20:38:27 +0000
From: Zax <fleegle@bananasplit.info>
References: <pan.2006.04.02.17.54.40.77007@eelbash.org> <D3AJK6WK38809.8851388889@anonymous.poster> <pan.2006.04.02.19.46.26.809359@eelbash.org> <e0parj$1ga$1@bananasplit.info> <pan.2006.04.02.20.11.19.208879@eelbash.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!news2.arglkargh.de!news.bananasplit.info!not-for-mail
Newsgroups: alt.privacy.anon-server
Organization: Bananasplit
Lines: 114
X-Complaints-To: abuse@bananasplit.info
NNTP-Posting-Date: Sun, 2 Apr 2006 20:38:27 +0000 (UTC)
User-Agent: slrn/0.9.8.1pl1 (Debian)
X-PGP-KeyID: 0x8ED57743