Need programming tip

S

ssaeed1973

I am trying to write a program in python (brand new to Python) that
would create a database of posts made to binary groups so the user can
search for a certain file and have a nzb file returned. I am planning
on using the XOVER command to get the list of posts and then dump those
into a database.
The part I am stuck at now is that some file posts consist of multiple
parts as below (abbreviated XOVER reply)

1511156 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (1/4) -
21/27
1511157 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (2/4) -
21/27
1511158 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (3/4) -
21/27
1511159 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (4/4) -
21/27

I am trying to detect how many segments make up this post. One solution
would be to look for (1/ in the subject string then find the
denominator and loop thru as many times as the denominator to create
the <segment> part of the nzb file. Is this the best way or is there an
easier method? Also what would be the best way to search for the (1/
using string searches or RegExp? If REgExp could someone provide me
with the RegExp for searching for this string?

Thanks
Salman
 
A

Alex Martelli

1511156 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (1/4) -
21/27
1511157 As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (2/4) -
21/27 ...
would be to look for (1/ in the subject string then find the
denominator and loop thru as many times as the denominator to create
the <segment> part of the nzb file. Is this the best way or is there an
easier method? Also what would be the best way to search for the (1/
using string searches or RegExp? If REgExp could someone provide me
with the RegExp for searching for this string?

If the only thing that identifies these posts as part of one logical
post is that (n/m) in the subject then I guess there's nothing for it
but analysis of the subject, and a re seems appropriate.

import re
re_n_of_m = re.compile(r'(.*)\s*\((\d+)/(\d+)\)')

might be one approach. Then, somewhere in your loop,

mo = re_n_of_m.search(subject)

sets mo to None if it doesn't match the pattern; if it does match, then
mo is a match object with three groups. mo.group(1) is the part of the
subject before the (n/m) marker; mo.group(2) is n as a string;
mo.group(3) is n as a string. You can use mo.group(1) as the key into a
dictionary where you collect (n,m) pairs as values, so that once you've
collected all posts you can tell which one are multipart and also check
for inconsistency (different m values), duplicates, missing parts. What
you need to do in each case, I don't know...


Alex
 
B

beliavsky

A Usenet tip is that one should never use such a generic subject as
"need programming tip" or the ever-popular "newbie question". In this
case, "create a database of posts made to binary groups" could have
been a better title, so that people unable to answer to the question
and not interested in the topic can skip it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top