两个贴东西的脚本

由本社区发起的开源项目
回复
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

两个贴东西的脚本

#1

帖子 BigSnake.NET » 2008-05-31 15:33

代码: 全选

#!/usr/bin/perl -w
#
# imgshack: Upload image files to imageshack.us.
#
# TODO: Add swf support.
#

use strict;

if (($#ARGV == -1) || ($ARGV[0] =~ /--help|-h/i )) {
    print <<HELP;
imgshack: Upload image files to imageshack.us.
Usage:
    imgshack [OPTION]... [FILE]...

Options:
    -h, --help      show this message.

Supported file types:
    jpg, jpeg, png, gif, bmp, tif, tiff.
HELP
    exit 0;
};

require LWP::UserAgent;

# my $type = qq[jpg|jpeg|png|gif|bmp|tif|tiff|swf] ;
my $type = qq[jpg|jpeg|png|gif|bmp|tif|tiff] ;
my $ua = LWP::UserAgent -> new;
$ua -> env_proxy;

foreach my $filename(@ARGV) {
    if (!(-r $filename && -f $filename)) { print STDERR "Fail: $filename: File dosen't exist or is not readable.\n"; next;};
    if (!($filename =~ m/\.($type)$/i)) { print STDERR "Fail: $filename: File type is not supported.\n"; next;};

    my $reply = $ua -> post( 'http://load.imageshack.us/' , 
        Content_Type => 'form-data',
        Content      => [ fileupload => ["$filename"] ]
    );
    if ($reply -> is_success ) {
        my $content = $reply -> content ;
        $content =~ s/\s+//g;
        if ($content =~ m'"([^"]+)"/></td><td[^>]*>Directlinktoimage'i) {
            print "$1\n";
        } else {
            print STDERR "Fail $filename: Could not get the URL of the image.\n";
        }
    } else { 
        print STDERR "Fail $filename: ".$reply -> status_line ."\n";
    };
};

代码: 全选

#!/usr/bin/perl -w
#
# Written by AutumnCat.
#

use strict;
use Getopt::Long;
require LWP::UserAgent;

my $help_message = <<HELP;
upaste: Paste text and images to http://paste.ubuntu.org.cn.

Usage:
    upaste [OPTION]... [FILES]...

Options:
    -lang LANGUAGE  set the language used for highlighting.
    -image FILE     screenshot image to upload.
    -name NAME      poster's name.
    -verbose        also print the urls of image and text files.
    -help           show this message.

If FILES is not specified or FILES is - , message will be read from standard input.

Available languages for the LANGUAGE argument:
    actionscript            ActionScript
    actionscript-french     ActionScript (French Doc Links)
    ada                     Ada
    apache                  Apache Log File
    applescript             AppleScript
    asm                     ASM (NASM based)
    asp                     ASP
    autoit                  AutoIT
    bash                    Bash
    blitzbasic              BlitzBasic
    c                       C
    c_mac                   C for Macs
    caddcl                  CAD DCL
    cadlisp                 CAD Lisp
    cfdg                    CFDG
    cpp                     C++
    csharp                  C#
    css                     CSS
    d                       D
    delphi                  Delphi
    diff                    Diff
    div                     DIV
    dos                     DOS
    eiffel                  Eiffel
    fortran                 Fortran
    freebasic               FreeBasic
    gml                     GML
    html4strict             HTML (4.0.1)
    inno                    Inno
    java                    Java
    java5                   Java 5
    javascript              Javascript
    lisp                    Lisp
    lua                     Lua
    matlab                  Matlab
    mpasm                   MPASM
    mysql                   MySQL
    nsis                    NullSoft Installer
    objc                    Objective C
    ocaml                   OCaml
    ocaml-brief             OCaml (Brief)
    oobas                   Openoffice.org BASIC
    oracle8                 Oracle 8
    pascal                  Pascal
    perl                    Perl
    php                     PHP
    php-brief               PHP (Brief version)
    python                  Python
    qbasic                  QBasic/QuickBASIC
    robots                  robots.txt
    ruby                    Ruby
    sas                     SAS
    scheme                  Scheme
    sdlbasic                SDLBasic
    smarty                  Smarty
    sql                     SQL
    tsql                    T-SQL
    vb                      VisualBasic
    vbnet                   VB.NET
    vhdl                    VHDL
    visualfoxpro            VisualFoxPro
    xml                     XML
HELP

my $poster="";
my $class="actionscript";
my $screenshot="";
my $verbose=0;
my $help=0;
my $optresult = GetOptions (
    "lang=s" => \$class,
    "image=s" => \$screenshot,
    "name=s" => \$poster,
    "verbose" => \$verbose,
    "help" => \$help
);

if ($help) {
    print $help_message;
    exit 0;
}

if (! $optresult) {
    print STDERR $help_message;
    exit 1;
}

# if ( $#ARGV == -1) {
#     print "Reading message from standard input, press CTRL-D to finish.\n";
# }

my @text = <> ;
chomp @text;
my $paste_url = 'http://paste.ubuntu.org.cn/';

my $ua = LWP::UserAgent -> new;
push @{ $ua->requests_redirectable }, 'POST';

my $r = $ua -> post(
    $paste_url,
    Content_Type => 'form-data',
    Content      => [
        paste       => "Send",    
        code2       => join("\n",@text) ,
        class       => $class ,
        screenshot  => [$screenshot] ,
        poster      => $poster
    ]
);
if ($r -> is_success ) {
    exit 1 if ( $paste_url eq ($r -> base) ) ;
    print $r -> base ."\n";
    if ($verbose) {
        if (($r -> content) =~ m'a class="alt" href="/(d\d+)"') {
            print "text:\t".$paste_url.$1."\n";
        }
        if (($r -> content) =~ m'a class="scr" href="/(i\d+)"') {
            print "image:\t".$paste_url.$1."\n";
        }
    }
} else {
    print STDERR "ERROR:\t".$r->status_line ."\n";
}
上次由 BigSnake.NET 在 2008-05-31 15:42,总共编辑 1 次。
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
xiooli
帖子: 6956
注册时间: 2007-11-19 21:51
来自: 成都
联系:

#2

帖子 xiooli » 2008-05-31 15:39

干啥玩意的?
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#3

帖子 BigSnake.NET » 2008-05-31 15:40

xiooli 写了:干啥玩意的?
看帮助啊..
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#4

帖子 millenniumdark » 2008-05-31 19:43

終於見到傳說中的求貓貼圖腳本了。加精。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#5

帖子 eexpress » 2008-05-31 20:55

球猫的脚本,也没见变动,怎么就是不发。 :lol: 吝啬
● 鸣学
头像
zhan
帖子: 1880
注册时间: 2005-08-15 0:04
来自: 南7技校

#6

帖子 zhan » 2008-05-31 21:18

。。。。 依依的加强版呢??

光会说别人。
飞得高,飞得低,学习再学习,多少大秘密!
http://zhan.blog.ubuntu.org.cn
头像
windwiny
帖子: 2254
注册时间: 2007-03-13 17:26

#7

帖子 windwiny » 2008-05-31 22:51

好玩
flyinflash
帖子: 2376
注册时间: 2006-09-21 14:28

#8

帖子 flyinflash » 2008-06-09 10:16

小猫今天考完试了,写个脚本放松一下
:D :D :D

功能:上传图片到 paste.ubuntu.org.cn 或者是 水区

更好的就是,作为 pidgin 的一插件,这样一来就大大方便聊天时图示了
:D :D :D :D
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#9

帖子 solcomo » 2008-07-11 17:00

研究研究 :D
回复