Thread: EAB File Server
View Single Post
Old 30 October 2017, 09:37   #1561
modrobert
old bearded fool

modrobert's Avatar
 
Join Date: Jan 2010
Location: Bangkok
Age: 52
Posts: 525
Turran,

I threw together a Python script 'eab_post_count.py' to get post count of a given EAB forum user.

This is kind of hairy in the sense that it depends on counting html tags and such on a dynamic webpage, pretty far from ideal, but it works (at the moment).

Code:
#!/usr/bin/env python 

import sys, re, urllib2

version="1.0"

if len(sys.argv) < 2:
    print(sys.argv[0] + ' v' + version +' by modrobert in 2017')
    print('Function: Returns the number of posts for a given EAB forum user.')
    print('Syntax: eab_user_count.py <username> [-i]')
    print('Options: -i ignore case sensivity in user name')
    print('Result: 0 = user found, 1 = user not found, 2 = invalid option.')
    sys.exit(1)
else:
    username = sys.argv[1]
    usernameurl = re.sub('[ ]', '%20', username)

eaburl = "http://eab.abime.net/memberlist.php?do=getall&pp=1&ausername=" + usernameurl

def parseurl(url):
    if not url:
        print("Empty URL!")
        return
    headers = { 'User-Agent' : 'Mozilla/5.0' }
    request = urllib2.Request(url, None, headers)
    response = urllib2.urlopen(request)
    content = response.read()
    return content

def pagesearch(content, trigger, start, end):
    sane = 0
    needlestack = []
    while sane == 0:
        curpos = content.find(trigger)
        if curpos >= 0:
            testlen = len(content)
            content = content[curpos:testlen]
            curpos = content.find('"')
            testlen = len(content)
            content = content[curpos+1:testlen]
            curpos = content.find(end)
            needle = content[0:curpos]
            result = content[len(start):curpos]
            if needle.startswith(start):
                needlestack.append(result)
        else:
            sane = 1
    return needlestack

def unescape(s):
    s = s.replace("&lt;", "<")
    s = s.replace("&gt;", ">")
    # this has to be last:
    s = s.replace("&amp;", "&")
    return s

eabcontent = parseurl(eaburl)

countlist = pagesearch(eabcontent, 'td class', 'alt2">', '</td>')
userlist = pagesearch(eabcontent, 'member.php?', '>', '</a>')

try:
    if sys.argv[2] == '-i':
        if unescape(str.lower(''.join(userlist))) != str.lower(username):
            print("User not found: " + username)
            sys.exit(1)
    else:
        print("Invalid option. ")
        sys.exit(2)
except Exception:
    if unescape(str(''.join(userlist))) != username:
        print("User not found: " + username)
        sys.exit(1)

for item in countlist:
    stripitem = re.sub('[,]', '', item)
    try:
        print(int(stripitem))
        sys.exit(0)
    except Exception:
        continue
Attached Files
File Type: zip eab_post_count_v1_0.zip (1.1 KB, 18 views)

Last edited by modrobert; 30 October 2017 at 15:30. Reason: Fixed bug, apparently a user with > 1000 posts get a ',' in their counter. Added handling of space in user name. Fixed "more than one hit" bug (thanks Turran).
modrobert is offline  
 
Page generated in 0.05126 seconds with 12 queries