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

Pages: 1-4041-

rename.py

Name: Anonymous 2007-12-07 1:33


import os, time
os.system("dir /p /l /o:n /w > directory.txt")
gg = open("directory.txt")
g = gg.readlines()
gg.close()
os.system("del directory.txt")
g = g[5:]
g = [x.strip() for x in g]
h = []
for x in g:
  xx = x.split()
  for xxx in xx:
    if xxx[0] != '[':
      if len(xxx) == 17:
        if xxx[-4:] in ['.png', '.gif', '.jpg']:
          h = h + [xxx]

g = h

j = []
for x in g:
  t = eval(x[:-7])
  tt = time.strftime("%y%b%d-%H.%M.%S", time.gmtime(t))
  # print x, t, tt
  j = j + [tt + x[-4:]]

rn = "rename %s %s"
for x in range(len(j)):
  j[x] = (os.path.abspath(g[x]), j[x])

j = [rn % x for x in j]

for x in j:
  os.system(x)


Look, it renames 4chan timestamp-named images to at least a human-readable format. TRY/CATCH BLOCKS ARE FOR FAGGOTS THIS WORKS FINE FOR ME AS LONG AS YOUR FOLDER DOESN'T CONTAIN ANY IMAGES WITH A 17-CHARACTER FILENAME THAT DOESN'T EVAL TO A PROPER TIMESTAMP. os.path.join() to taste, and chill for two hours. Cut into slices. Serves 12.

Name: Anonymous 2007-12-07 4:24

in b4 FIOC, /prog/snake, etc.

Name: Anonymous 2007-12-07 4:53

ONE WORD, FORCED INDENTATION OF THE CODE, THREAD OVER

Name: Anonymous 2007-12-07 4:59

Why do you must import the time library everywhere?

Name: Anonymous 2007-12-07 5:00

time waits for no man

Name: Anonymous 2007-12-07 5:16

time should be discarded from the standard library.

Name: Anonymous 2007-12-07 5:46

Enjoy your forced indentation of code.


use strict;
use warnings;
use Date::Format qw(time2str);
use File::Copy qw(move);

my $folder = "/tmp/4chan";

opendir my $dirh, $folder
    or die $!;

my @imgs = grep { /^\d+\.(png|jpg|gif)/ } readdir $dirh;
closedir $dirh;

foreach my $img (@imgs) {
    my ($time, $ext) = $img =~ /(\d+).(\w+)/;
    next unless $time and $ext;

    my $hr = time2str("%y%b%d-%H.%M.%S", $time / 1000);
    move("$folder/$img", "$folder/$hr.$ext");
}

Name: Anonymous 2007-12-07 6:39

>>45,

Lolled at the reply.

Name: Anonymous 2007-12-07 9:25

>>7
Is that Haskell?

Name: Anonymous 2007-12-07 11:07

>>1
This is some horrible Python.

Name: Anonymous 2007-12-07 11:19

>>1
this is why i despise python

Name: Anonymous 2007-12-07 11:29

post more 4chan stuff in this thread
#!/bin/sh
# script to fetch threads from 4chan

URL=$1
GREP=$2
PROGRAM=`basename $0`
TMPFILE=`mktemp -t "$PROGRAM.out"`

clean_exit() {
    rm "$TMPFILE"
    exit
}

if [ -z $URL ]; then
    echo "Usage: `basename $0` <URL> [pattern]"
    exit
fi

trap 'clean_exit' 2

echo "Fetching $URL to $TMPFILE"
fetch -mq -o "$TMPFILE" "$URL"

for i in `cat "$TMPFILE" | grep 'File :<a href' | sed 's/.*File :<a href="\([^"]*\)" target=.*<span title="\([^"]*\)">\([^"]*\)<\/span>.*/\2<SEP>\1/' | tr ' ' '_'`; do
    `echo "$i" | grep "$GREP" | sed "s/\(.*\)<SEP>\(.*\)/fetch -mo \1 \2/"`
done

clean_exit

Name: Anonymous 2007-12-07 11:32

>>11
And IOCCC is why you despise C?

Name: Anonymous 2007-12-07 11:42

>>1
Okay..., you have enraged me.

1) You used Python.  Python is clearly inappropriate for this task.
2) Your code looks like shit, learn to code; read SICP.
3) ``images,'' who the hell wants images here in /prog/?
4) Real men use timestamps internally (in their heads, that is), and convert real dates to timestamps.

Name: Anonymous 2007-12-07 11:53

>>1
Doesn't work fine, it is not platform independant. Also, the code is horrible. FAIL PROGRAMMER

Name: Anonymous 2007-12-07 12:29

>>1

for x in g:
  xx = x.split()
  for xxx in xx:
    if xxx[0] != '[':
      if len(xxx) == 17:
        if xxx[-4:] in ['.png', '.gif', '.jpg']:
          h = h + [xxx]

lol var names x, xx and xxx. LOL WHUT?
Also you have no comments except for a out commented debug line.
Clearly you are not an EXPERT PROGRAMMER

Name: Anonymous 2007-12-07 12:39

>>16
What? To the compiler, the actual name of a variable does not matter, and this should also be the case for an EXPERT PROGRAMMER

Name: Anonymous 2007-12-07 12:54

>>17
What? An expert programmer would think of a descriptive name before a bunch of "x"s. “Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.”

Name: Anonymous 2007-12-07 13:18

>>18
Descriptive variables names??? They're for NOOB PROGRAMMERS

Name: Anonymous 2007-12-07 14:55

PROTIP: Make functions small enough so that variable names don't need to be descriptive.

Name: Anonymous 2007-12-07 18:13

>>20
PROTIP: Then make them descriptive anyway.

Name: Anonymous 2007-12-07 20:33

>>19
or for people with >30 lines of code in their program.

Name: Anonymous 2007-12-07 21:44

os.system("del directory.txt")
Go die in a fire.

Name: Anonymous 2007-12-08 7:25

This is a prime example of how forced indentation of code makes better programs.

Name: Anonymous 2007-12-08 9:35

>>24
2 isn't a prime number since it's even

Name: Anonymous 2007-12-08 9:52

>>25
facepalm.jpg

Name: Anonymous 2007-12-08 15:56

>>26
faggot.jpg

Name: Anonymous 2007-12-08 18:33

>>27
facepalm.jpg

Name: Anonymous 2007-12-08 18:57

>>28
faggot.pl

Name: Anonymous 2007-12-08 19:03

>>29
facepalm.rar

Name: Anonymous 2007-12-08 19:04

notepad.exe

Name: Anonymous 2007-12-08 19:11

>>30
What's the password?

>>31
Fuck off with your malware.

Name: Anonymous 2007-12-08 21:28

Absolutely no reason to call external programs. Python seriously does bring out some bad programmers. ITS SO GOD DAMN EASY, sure, you still did it wrong.

Name: Anonymous 2007-12-09 0:14

>>7
my@mname=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
for$dir(@ARGV){
 for(grep/\/\d+\.(?:gif|jpg|png)$/,glob"$dir/*"){
  my($time,$ext)=$_=~/\/(\d+)\.(gif|jpg|png)$/;
  my($year,$mon,$mday,@rest)=reverse map${[gmtime substr$time,0,10]}[$_],0..5;
  rename("$dir/$time.$ext","$dir/${\($year+1900)}$mname[$mon]$mday-${\join'.',map{sprintf'%2u',$_}@rest}.$ext")
 }
}

Name: Anonymous 2007-12-09 3:10

>>34
my@mname=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
for(@ARGV){
 for(grep/\/\d+\.(?:gif|jpg|png)$/,glob"$_/*"){
  (my$newname=$_)=~s/(\d+)(....)$/"${\((gmtime$1\/1000)[5]+1900)}${\($mname[(gmtime$1\/1000)[4]])}${\((gmtime$1\/1000)[3])}-${\(join'.',map{sprintf'%2u',$_}reverse map{(gmtime$1\/1000)[$_]}0..2)}$2"/e;
  rename$_,$newname;
 }
}

Name: Anonymous 2007-12-09 3:26

>>35
actually, this works too:
(my$newname=$_)=~s/(\d+)(....)$/${\((gmtime$1\/1000)[5]+1900)}${\($mname[(gmtime$1\/1000)[4]])}${\((gmtime$1\/1000)[3])}-${\(join'.',map{sprintf'%2u',$_}reverse map{(gmtime$1\/1000)[$_]}0..2)}$2/;

Name: Anonymous 2007-12-09 16:24

>>34,35
I don't know if this is any shorter, but it was fun making it :)

$f=@ARGV[0]and$r=qr{\/(\d+).(jpg|png|gif)}and$a=join'',grep/$r/,glob"$f/*";
while($a=~/$r/g){($d,$e)=($1,$2)and$_=gmtime$d/1000;
    m/ (\w{3})\s+(\d+) (\d+):(\d+):(\d+) \d{2}(\d{2})/;
    $n=join'',$6,$1,(sprintf"%02d",$2),"-$3.$4.$5";
    rename"$f/$d.$e","$f/$n.$e";
}

Name: 37 2007-12-09 16:29

I like yours better though :P

Name: Anonymous 2007-12-09 16:35

>>37
Valid perl cod

Name: Anonymous 2007-12-09 17:46

>>49
You can tune a fish, but you can't cod fish.

Name: Anonymous 2007-12-09 18:18

#!/usr/bin/perl
my@mname=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec
');
for(@ARGV){
 for(grep/\/\d+\.(?:gif|jpg|png)$/,glob"$_/*"){
  (my$newname=$_)=~s/(\d+)...(....)$/${\((gmtime$1)[5]+1900)}${\($mname[(gmtime$
1)[4]])}${\((gmtime$1)[3])}-${\(join'.',map{0 x($_<10).$_}reverse map{(gmtime$1)
[$_]}0..2)}$2/;
  rename$_,$newname;
 }
}

splice(gmtime$1),0,3

Name: Anonymous 2007-12-09 18:56

/\/\d+\.(?:gif|jpg|png)$/

what does the highlighted flag in regexp do? I forget :(

Name: Anonymous 2007-12-09 18:56

>>40
This may surprise you, but I invented that meme.

Name: Anonymous 2007-12-09 18:57

>>42

Ignores the group (i.e. you can't reference it later)

Name: Anonymous 2007-12-09 19:15

FORCED INDENTATION OF CODE
displeases
the
MASTER PROGRAMMER

Name: Anonymous 2007-12-12 8:33

This thread hurts my brain.

Name: Anonymous 2009-02-19 14:33

Name: Anonymous 2009-03-06 8:13

The bus driver looked   strangely familiar as   I dropped the   coins into the   interpreter and rebuild   the damn thing   bind Instead of   singletons I mean   are there people   need to learn   but falls short   on performance and   in maintainability For.

Name: Anonymous 2009-03-06 9:52


Heads in ascii So.

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