Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Anti-shitpost league

Name: Anonymous 2012-03-20 6:11

Share some 'really quick hack' scripts you have made.

Scrape gelbooru for images based on a tag search list

import os
import sys
import re
import urllib
import urllib2
tagsfile = open('tags.txt', 'r')
tags = tagsfile.read().split('\n')
for tag in tags:
    pid = 0
    keepgoing = 1
    while keepgoing:
        print 'sp', 'http://gelbooru.com/index.php?page=post&s=list&tags='+tag+'&pid='+str(pid)
        searchpage = urllib2.urlopen('http://gelbooru.com/index.php?page=post&s=list&tags='+tag+'&pid='+str(pid)).read()
        searchpids = re.findall('<a id="p(\\d+)"', searchpage)
        if len(searchpids) == 0:
            keepgoing = 0
        for searchpid in searchpids:
            print 'ip', 'http://gelbooru.com/index.php?page=post&s=view&id='+searchpid
            imagepage = urllib2.urlopen('http://gelbooru.com/index.php?page=post&s=view&id='+searchpid).read()
            imageurl = re.findall('<a href="(
[^"]+)"[^>]+>Original image</a>', imagepage)[0]
            print 'i', imageurl
            urllib.urlretrieve(imageurl, 'out/' + imageurl.split('/')
[-1])
        pid += 28[code]

[b]Rename all files in a directory to its md5 hash[/b]

[code]import os
import sys
import hashlib
failed = ''
for fn in os.listdir(sys.argv
[1]):
    md5 = hashlib.md5()
    ffn = os.path.join(sys.argv
[1], fn)
    fext = os.path.splitext(fn)
[1]
    with open(ffn, 'rb') as f:
        for chunk in iter(lambda: f.read(128 * md5.block_size), ''):
            md5.update(chunk)
    fhash = md5.hexdigest()
    try:
        fnn = fhash + fext
        print fn, '=>', fnn
        os.rename(ffn, os.path.join(sys.argv
[1], fnn))
    except:
        failed += 'failed: ' + fn + '\n'
print failed

Name: bbcode failure 2012-03-20 6:13

Share some 'really quick hack' scripts you have made.

Scrape gelbooru for images based on a tag search list

import os
import sys
import re
import urllib
import urllib2
tagsfile = open('tags.txt', 'r')
tags = tagsfile.read().split('\n')
for tag in tags:
    pid = 0
    keepgoing = 1
    while keepgoing:
        print 'sp', 'http://gelbooru.com/index.php?page=post&s=list&tags='+tag+'&pid='+str(pid)
        searchpage = urllib2.urlopen('http://gelbooru.com/index.php?page=post&s=list&tags='+tag+'&pid='+str(pid)).read()
        searchpids = re.findall('<a id="p(\\d+)"', searchpage)
        if len(searchpids) == 0:
            keepgoing = 0
        for searchpid in searchpids:
            print 'ip', 'http://gelbooru.com/index.php?page=post&s=view&id='+searchpid
            imagepage = urllib2.urlopen('http://gelbooru.com/index.php?page=post&s=view&id='+searchpid).read()
            imageurl = re.findall('<a href="([^"]+)"[^>]+>Original image</a>', imagepage)[0]
            print 'i', imageurl
            urllib.urlretrieve(imageurl, 'out/' + imageurl.split('/')[-1])
        pid += 28


Rename all files in a directory to its md5 hash

import os
import sys
import hashlib
failed = ''
for fn in os.listdir(sys.argv[1]):
    md5 = hashlib.md5()
    ffn = os.path.join(sys.argv[1], fn)
    fext = os.path.splitext(fn)[1]
    with open(ffn, 'rb') as f:
        for chunk in iter(lambda: f.read(128 * md5.block_size), ''):
            md5.update(chunk)
    fhash = md5.hexdigest()
    try:
        fnn = fhash + fext
        print fn, '=>', fnn
        os.rename(ffn, os.path.join(sys.argv[1], fnn))
    except:
        failed += 'failed: ' + fn + '\n'
print failed

Name: Anonymous 2012-03-20 6:23

Your scripts are absolute shit.

Name: Anonymous 2012-03-20 6:24

>>3
In terms of code quality? Yes. In terms of pragmatic functionality? Hardly. It gets the job done -- the value to development time ratio is very high.

Name: Anonymous 2012-03-20 6:31

>>4
In terms of anything, it's objectively shit.

Name: Anonymous 2012-03-20 6:31

>>5
What have you written that is useful, at least, for your personal use?

Name: Anonymous 2012-03-20 6:46

Well, I'm not expert but, I thing your codes are readable.
Thanks for sharing.

Name: Anonymous 2012-03-20 7:52

>>5
Nope. Your assertion is meaningless.

>>6
It's best to ignore useless attacks like that. Accept only constructive criticism that'll actually help you improve yourself.

Name: Anonymous 2012-03-20 8:35

I don't see any sort of threading in your code. Thus, it is shit, and will always be shit.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List