Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Gist Creator

by alexbio (Monk)
on May 11, 2010 at 18:37 UTC ( #839490=CUFP: print w/ replies, xml ) Need Help??

Update: This code has been merged to WWW::GitHub::Gist.

Update: I've updated the code, see Re: Gist Creator for more info.

Hi all. This script creates a gist on GitHub from a file. Full documentation is included as POD.

Here you can find its git repository.

#!/usr/bin/perl # Create a Gist on GitHub.com from a file. # # Copyright 2010 Alessandro Ghedini <al3xbio@gmail.com> # -------------------------------------------------------------- # "THE BEER-WARE LICENSE" (Revision 42): # Alessandro Ghedini wrote this file. As long as you retain this # notice you can do whatever you want with this stuff. If we # meet some day, and you think this stuff is worth it, you can # buy me a beer in return. # -------------------------------------------------------------- use WWW::GitHub::Gist; use strict; die "For info type 'perldoc $0'\n" unless $#ARGV > 0; my ($file, $login, $token, $ext); $login = $ENV{GITHUB_USER}; $token = $ENV{GITHUB_TOKEN}; for (my $i = 0; $i < $#ARGV + 1; $i++) { $file = $ARGV[$i+1] if ($ARGV[$i] eq "-f"); $login = $ARGV[$i+1] if ($ARGV[$i] eq "-l"); $token = $ARGV[$i+1] if ($ARGV[$i] eq "-t"); $ext = $ARGV[$i+1] if ($ARGV[$i] eq "-e"); die "For info type 'perldoc $0'\n" if ($ARGV[$i] eq "-h"); } open(FILE, $file) or die "ERROR: Enter a valid file name."; my $data = join('', <FILE>); close FILE; my $basename = (split /\//, $file)[-1]; if ($ext eq '') { $ext = ".".($file =~ m/([^.]+)$/)[0]; print "Found $ext extension. You can provide custom extension usin +g '-e' option.\n"; } my $gist = WWW::GitHub::Gist -> new(user => $login, token => $token); $gist -> add_file($basename, $data, $ext); $gist -> create; my $repo = $gist -> {'repo'}; print "Gist $repo successfully created.\n"; print "Public Clone URL: git://gist.github.com/$repo.git\n"; print "Private Clone URL: git\@gist.github.com:$repo.git\n"; __END__ =head1 NAME Gist.pl - Create a Gist on GitHub.com from a file. =head1 USAGE Gist [OPTIONS] =head1 OPTIONS =over =item -l Specifies the username. =item -t User's GitHub API token, used for login. =item -f File to upload. =item -e File extension, used for syntax highlighting (optional). =back =head1 CONFIGURATION Username and api token variables could be set via the GITHUB_USER and GITHUB_TOKEN environment variables. These settings are overwritten by +the ones passed via command-line. =head1 TOKEN API token can be found on the Account Settings page. Visit the url: https://github.com/account =head1 EXTENSION The extension variable is used by GitHub to set proper syntax highlighting rules. This script obtain it automatically from the file extension, but the user could manually provide the extension using the '-e' option. GitHub supports the following extensions/languages: .txt Plain Text .as ActionScript .c C .cs C# .cpp C++ .css CSS .cl Common Lisp .diff Diff .el Emacs Lisp .hrl Erlang .html HTML .hs Haskell .java Java .js JavaScript .lua Lua .m Objective-C .php PHP .pl Perl .py Python .rb Ruby .sql SQL .scala Scala .sls Scheme .tex TeX .xml XML .ascx ASP .scpt AppleScript .arc Arc .asm Assembly .bat Batchfile .befunge Befunge .boo Boo .b Brainfuck .ck ChucK .clj Clojure .coffee CoffeeScript .cfm ColdFusion .feature Cucumber .d D .darcspatch Darcs Patch .pas Delphi .duby Duby .dylan Dylan .e Eiffel .f FORTRAN .s GAS .kid Genshi .ebuild Gentoo Ebuild .eclass Gentoo Eclass .po Gettext Catalog .go Go .man Groff .mustache HTML+Django .erb HTML+ERB .phtml HTML+PHP .hx HaXe .haml Haml .ini INI .weechatlog IRC log .io Io .ll LLVM .mak Makefile .mao Mako .ron Markdown .matlab Matlab .mxt Max/MSP .md MiniD .moo Moocode .myt Myghty .nu Nu .numpy NumPy .ml OCaml .j Objective-J .pir Parrot Internal Representation .pd Pure Data .pytb Python traceback .r R .rhtml RHTML .raw Raw token data .cw Redcode .sass Sass .self Self .sh Shell .st Smalltalk .tpl Smarty .sc SuperCollider .tcl Tcl .tcsh Tcsh .txt Text .vhdl VHDL .v Verilog .vim VimL .bas Visual Basic .yml YAML .jsp jsp .mu mupad .ooc ooc .rst reStructuredText =cut
Alex's Log - http://alexlog.co.cc

Comment on Gist Creator
Download Code
Re: Gist Creator
by alexbio (Monk) on Jun 08, 2010 at 18:37 UTC

    I've made just a little update.

    Now the script is based on the WWW::GitHub::Gist module, I wrote.

    You can find the previous version here.

    Alex's Log - http://alexlog.co.cc

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://839490]
Approved by planetscape
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2014-09-22 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls