Jump to content




Pastebin Api

api lua utility

17 replies to this topic

#1 AgentE382

  • Members
  • 119 posts

Posted 05 October 2013 - 05:55 PM

Pastebin API


This is a full implementation of the Pastebin API as described at http://pastebin.com/api

Note that this is a first release, mostly untested, and only provides minimum functionality. In the future, I will improve on the existing functions and add helper functions for common tasks.

pastebin get 5SJ0d1mV pb
http://pastebin.com/5SJ0d1mV
Spoiler

Changelog:
0.8 - 11-06-2016 - Added getprivate() function.
0.7 - 10-11-2013 - Added HTTP error checking to get().
0.6 - 10-08-2013 - Fixed list() bug: Accidental reference to old parser.
0.5 - 10-07-2013 - Fixed get() returning wrong data bug.
0.4 - 10-06-2013 - Added version number.
10-06-2013 - Replaced custom URL-Encoder with CC-Lua's textutils.urlEncode().
10-06-2013 - Fixed input validation bug for list().
10-05-2013 - First release.

Edited by AgentE382, 11 June 2016 - 04:32 AM.


#2 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 06 October 2013 - 01:25 AM

Sick.

#3 campicus

  • Members
  • 164 posts

Posted 07 October 2013 - 07:10 PM

I don't know how it works but this is super helpful!

#4 AgentE382

  • Members
  • 119 posts

Posted 07 October 2013 - 07:56 PM

Anyone who downloaded this before now should update. If the output of the get() and list() functions looked funky, that's because they were broken.

I'm really sorry about that.

Oh, and I added one example to the post. I'll add more examples and helper functions over time.

#5 campicus

  • Members
  • 164 posts

Posted 08 October 2013 - 07:25 AM

I cannot use the list() function with this code:

os.loadAPI("pastebinAPI")
local pb = pastebinAPI

local legg0028 = pb.login("legg0028", "notActuallyMyPW")
print(legg0028)

local allPastes = pb.list(legg0028, 1000)

I get the error: pastebinAPI:80: attempt to index ? (a nil value)

#6 mwa

  • Members
  • 5 posts

Posted 08 October 2013 - 03:23 PM

that's realy usefull thanks you guy!

#7 AgentE382

  • Members
  • 119 posts

Posted 08 October 2013 - 10:16 PM

Fixed again. I thought I had deleted that old code.

Again, everyone should update immediately.

#8 titimoby

  • Members
  • 6 posts
  • LocationFrance, Villeurbanne

Posted 09 October 2013 - 03:40 AM

Is it safe for you to let your API key in the pastebin code ?

#9 AgentE382

  • Members
  • 119 posts

Posted 09 October 2013 - 06:35 AM

Not really, but I couldn't think of a good way to obfuscate it. Besides, anyone can have their own for free, so... it didn't seem worth it.

#10 titimoby

  • Members
  • 6 posts
  • LocationFrance, Villeurbanne

Posted 09 October 2013 - 06:59 AM

I think it's a good practice to just put <insert your own api key here> in the code or define a parameter.
If anyone get the key to try unapproved pastebin action, you will be blamed for that.

By the way, nice code.
I just start with ComputerCraft with my kid and we look for several ways to backup on our home computer our programs.
Your code is a good start to understand APIs

#11 campicus

  • Members
  • 164 posts

Posted 14 October 2013 - 07:49 PM

Just an example of what this program allows you to do! This is an automatic updater which updates all my codes from pastebin!
Please note I use your api as functions within my program, which I won't post.

term.clear()
term.setCursorPos(1,1)
print("Preparing to update programs...")

local legg0028 = login("legg0028", "notMyPW") --login
local allPastes = list(legg0028,1000) --"put all pastes in a table"

if fs.exists("/disk/camp/updates") then --"remove the old updates folder"
  fs.delete("/disk/camp/updates")
end
fs.makeDir("disk/camp/updates") --"make a new updates folder"

for i,v in ipairs(allPastes) do --"for each of my pastes download it and save it (with the name it has on pastebin)"
  code = http.get("http://pastebin.com/raw.php?i="..allPastes[i]["key"])
  if code then
	h = fs.open("disk/camp/updates/"..allPastes[i]["title"],"w")
	h.write(code.readAll())
	h.close()
	print("\""..allPastes[i]["title"].."\" successfully downloaded")
  else
	print(allPastes[i]["title"] "failed to download")
  end
end

local allPrograms = fs.list("disk/camp/updates/") --"copy from the updates folder into my working folder"
print(allPrograms[1])
for i,v in ipairs(allPrograms) do
fs.delete("/disk/camp/"..allPrograms[i])
fs.copy("/disk/camp/updates/"..allPrograms[i], "/disk/camp/"..allPrograms[i])
print("\""..allPrograms[i].."\" successfully updated")
end

print("successfully updated "..#allPrograms.." programs.")


#12 AgentE382

  • Members
  • 119 posts

Posted 16 October 2013 - 07:41 AM

View Posttitimoby, on 09 October 2013 - 06:59 AM, said:

<snip>
By the way, nice code.
<snip>

View Postcampicus, on 14 October 2013 - 07:49 PM, said:

Just an example of what this program allows you to do!
<snip>

Thanks, guys! Glad it's been useful to you!

#13 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 16 October 2013 - 10:10 AM

Actually, you can provide your own developer key to anyone. It doesn't mean anything, and it cannot affect your account in any way. The only thing it does is allow Pastebin to track which developers are using their API.

You'll note that there is a developer key in the default pastebin program in ComputerCraft.

#14 xXLeNinjaXx

  • Members
  • 33 posts

Posted 12 January 2014 - 04:35 PM

Cranium Any way to make an auto updater for me :I

#15 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 12 January 2016 - 12:31 PM

Hey, I'm trying to make a computercraft pastebin client out of this. How exactly do I update a post once logged in through pastebin.login()?
Here's the code I have so far.

#16 AgentE382

  • Members
  • 119 posts

Posted 11 June 2016 - 04:29 AM

View PostEldidiStroyrr, on 12 January 2016 - 12:31 PM, said:

Hey, I'm trying to make a computercraft pastebin client out of this. How exactly do I update a post once logged in through pastebin.login()?
Here's the code I have so far.
EldidiStroyrr, that looks cool. I haven't checked this forum in ages and apparently wasn't subscribed to my own thread...

Anyway, Pastebin doesn't offer an official API for that, but now that this has caught my eye, I'll take a look at what happens when you use the "edit" button on their site and see if I can implement that in CC-Lua.

Even if you don't end up using it, I'll post it up when I figure it out seeing as it might be useful for me or someone else.

Edited by AgentE382, 11 June 2016 - 04:29 AM.


#17 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 11 June 2016 - 03:23 PM

If you ever figure out how to edit posts, I'll be sure to add that to PasteCCan!

#18 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 22 January 2018 - 02:31 PM

I apologize for necro, but the pastebin API switched to HTTPS. Update your API to reflect that, please.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users