github3.py doesn't return file content for gist - github3.py

I use github3.py library in order to create and update Gist on github.com
I can access an existing gist and get all information except content of the file:
for g in gh.iter_gists():
if g.id == content[0]:
f = g.iter_files().next()
print g.files #1
print f.raw_url
old_content = f.content #Returns None
Any hint why does it return None in the last line?

It looks as though GitHub's API no longer returns the contents of the gist file as part of the response:
{u'size': 12, u'raw_url': u'https://gist.githubusercontent.com/testgh3/eb911d34ec732e4b7f24/raw/e041e7dc6236db21062c11b2929a72e656bbc40e/fileA.txt', u'type': u'text/plain', u'language': u'Text', u'filename': u'fileA.txt'}
This means that github3.py needs to add functionality to the GistFile class that you're trying to use here. (I've already created an issue for this. If you'd like to help do the work, I'm happy to help you with that and I'd love to merge a pull request with this functionality.)

Related

How to delete generated bitstreams in DSpace 6x?

I would like to delete all the bitstreams generated by filter-media but only with a specific description "IM Thumbnail".
I am aware that I can just regenerate the thumbnail by using the -f flag to force it to regenerate the thumbnail. I am testing some settings in my setup and I would just like to delete the generated thumbnails with this specific description first.
I've tried tinkering the database via PgAdmin but I can only go as far as selecting the bitstreams. I don't even know how to group or order the returned results and not really sure if I've selected the correct tables.
SELECT
*
FROM
public.bitstream,
public.bundle,
public.bundle2bitstream,
public.metadatavalue,
public.item2bundle
WHERE
bitstream.uuid = metadatavalue.dspace_object_id AND
bitstream.uuid = bundle2bitstream.bitstream_id AND
bundle.uuid = item2bundle.bundle_id AND
bundle2bitstream.bundle_id = bundle.uuid AND
metadatavalue.text_value = 'IM Thumbnail';
Any advice on how to do this via database manipulation or any other means would be greatly appreciated. Applying the SQL deletion within a specific community or collection would be a really nice bonus too!
Thanks in advance!
Although the question was tagged with postgresql, I found the answer from DSpace Community Mailing List using Jython. Thanks for Joan Caparros for the original code. The message thread can be found here: Removing Thumbnails in DSpace 5. I also posted a similar query in the DSpace Technical Support Mailing List which can be found here: Batch delete bitstreams in the Bundle: THUMBNAIL where Joan posted a modified version of his code for my specific needs which is deleting only the thumbnails if it contains the description "IM Thumbnail". Below is the full code that achieved my goals:
from org.dspace.curate import ScriptedTask
from org.dspace.curate import Curator
from org.dspace.content.service import DSpaceObjectService
from org.dspace.content.factory import ContentServiceFactory
#from org.dspace.content.service import BitstreamService
class Main(ScriptedTask):
def init(self, curator, taskName):
print "initializing with Jython"
def performDso(self, dso):
#print "perform on dso "
if dso.getType()==2:
print "Item '" + dso.getName() + "' ("+dso.getHandle()+")"
myBundles = dso.itemService.getBundles(dso,"THUMBNAIL")
totalbundles = len(myBundles)
for i in myBundles:
myBitstreams = i.getBitstreams()
total = len(myBitstreams)
if len(myBitstreams)==0:
print "- DELETING EMPTY BUNDLE"
dso.itemService.removeBundle(Curator.curationContext(),dso,myBundles[0])
if len(myBitstreams)>0:
for k in range(0,len(myBitstreams)):
if myBitstreams[k].getDescription() == 'IM Thumbnail':
print "DELETE "+myBitstreams[0].getDescription()
bitstreamService = ContentServiceFactory.getInstance().getBitstreamService()
bitstreamService.delete(Curator.curationContext(),myBitstreams[0])
print "- DELETING BUNDLE"
dso.itemService.removeBundle(Curator.curationContext(),dso,myBundles[0])
return 0
def performId(self, context, id):
print "perform on id %s" % (id)
return 0
Please note that the code above was made as a curation task using Jython so the documentation on how to set up and use can be found here: Curation tasks in Jython.

Construct a single table with a loop with R and Rfacebook package

I use Rfacebook package to download Facebook Fanpages posts . I also want to get the comments and likes of the posts, but I only have working code to get single comments and I fail to create a loop.
I ll post all steps one by one and keep my token updated for the next several hours.
#Step1
install.packages("Rfacebook")
install.packages("Rook")
install.packages("igraph")
#start the libaries
library(Rfacebook)
library(Rook)
library(igraph)
After installtion I can generate a token (use mine) and download the FB page humans of new york for example:
#step 2
#browse to facebook and ask for token
#browseURL("https://developers.facebook.com/tools/explorer")
token <- "CAACEdEose0cBACzNgrHPBIZAQCQ8EZBpGJqwwT8uVq74ONdKJKDk6fiXXgjBB4ZBHC93Njd2onrhGsiffK5QFqpIvZBCFEagBkOqMgjaf103XwpHhSV6YOeVdcjU813g6eJKCsdtNT7pGRYftTXgZBrSMMOyAj47mAZBGxI98iPv78qTeIqliA8UCbZBzZAVU0NoOUBTkJSPPQZDZD"
#get FB fanpage "humansofnewyork"
humansofnewyork <- getPage("humansofnewyork", token, n=500)
Now I want to create a loop that will download every comment and like for every postid. But when I run a loop append I will get a table which will replicate the colomuns horizontally at certain point instead of just adding rows vertically.
users.humansofnewyork = c()
for (i in 1:3) {
users.humansofnewyork = append(users.humansofnewyork, getPost( (humansofnewyork$id[i]) , token, n = 500, comments = TRUE,likes = TRUE, n.likes=500, n.comments=500))
}
I would be so glad if someone can help me.
Kind regards
use 'plyr' package in R, which helps in splitting the data. It has helped me till this moment.
use the following code
apply<-ldply(users.humansofnewyork,data.frame)

typo3: how does this work: $GLOBALS['TSFE']->tmpl?

in one extension file: I run below code:
var_dump($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_watermark_pi1.']);
the result is :
["hooks."]=> array(4) { ["dagou_post."]=> array(1) { ["view."]=> array(2) { ["state."]=> array(1) { ["template"]=> string(11) "###INPUT###" }...
and I can tell it outputs this file: ext_typoscript_setup.txt inside extension:watermark and also the ts settings from global and local pages.
Question:
I checked file: typo3\sysext\cms\tslib\class.tslib_fe.php, and trying to figure out how does this work: $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_watermark_pi1.'], but only saw var $tmpl='';
from this code: $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_watermark_pi1.'], tmpl should be an object, and setup['plugin.']['tx_watermark_pi1.'] should be the property. So anyone can give me some explanation on how does $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_watermark_pi1.'] work? thanks.
$GLOBALS['TSFE']->tmpl->setup is the cumulative recursive TS setup of your compete website. It gathers all TS templates, found in rootline from your current selected page, parses it and compiles into array.
Obviously, you will find nothing about tx_watermark_pi1 in class.tslib_fe.php, because tslib_fe knows nothing about it - it just creates FE, and one of the tasks is to create tmpl object, that contains complete setup of all TS, found in rootline.
You can find more info on TS parsing here
The typoscript code you write and also the ts-files delivered with the extensions you have installed are parsed to php and then cached. When the frontend is built up, this very big php array is written to this global object and then read from there by several other classes like extension plugins and so on.
You can find that code in the t3lib/class.t3lib_tsparser*.php classes if you want to take a look (although I don't think that will help you).

How to add some extra parameter in the airbrake parameters for JS errors

When we are sending the airbrake error to the airbrake server, by default it includes the controller name and action name.
But the question is that I want to add some extra parameters like username, email of the current user. If anyone has any idea please suggest how to do that?
In my layout application.html:
- if ['development'].include?(Rails.env)
= airbrake_javascript_notifier
= render :partial => 'layouts/airbrake_notifier'
and in the partial I have written:
Airbrake.errorDefaults['name'] = "#{current_user.name}";<br/>
Airbrake.errorDefaults['email'] = "#{current_user.email}";<br/>
Airbrake.errorDefaults['phone'] = "#{current_user.phone}";<br/>
Airbrake.errorDefaults['title'] = "#{current_user.title;<br/>
Not a great solution, but the Airbrake Knowledge Base recommends essentially patching the airbrake gem source of the lib/airbrake/notice.rb file.
def initialize(args)
...
self.parameters = args[:parameters] ||
action_dispatch_params ||
rack_env(:params) ||
{'username' => current_user.name}
It would certainly be better to have this be configurable without patching source.
What I've done instead is simply add a few pieces of data to the session (current_user.name mainly), since session data is sent with the request. I wouldn't do this for more than a few little pieces of data.
We've just added getting current users into the Airbrake Gem.
https://github.com/airbrake/airbrake/wiki/Sending-current-user-information
You'll soon be able to sort by current user in an upcoming redesign of the UI.

How can I Diff a Svn Repository using SharpSvn

My question is quite simple and with the SharpSvn Api, it should be easy as well. Here what I did:
path = "c:\project";
using (SvnLookClient client = new SvnLookClient())
{
SvnLookOrigin o = new SvnLookOrigin(path);
Collection<SvnChangedEventArgs> changeList;
client.GetChanged(o, out changeList); // <-- Exception
}
and when I call the GetChanged, I get an exception:
Can't open file 'c:\project\format': The system cannot find the file specified.
So, Maybe there is something I'm missing? Or maybe it's not the right way to do find out the list of files and folders that were modified in the local repository?
Thanks in advance.
The SvnLookClient class in SharpSvn is the equivalent to the 'svnlook' console application. It is a low level tool that enables repository hooks to look into specific transactions of a repository using direct file access.
You probably want to use the SvnClient class to look at a WorkingCopy and most likely its Status() or in some cases simpler GetStatus() function to see what changed.
The path that the SvnLookOrigin constructor wants is actually:
path = "c:\project\.svn\";
That is, it wants that special ".svn" directory not just the root of where the source is checked out to.
Although you probably do want to listen to Bert and do something like:
path = "c:\project";
using (SvnLookClient client = new SvnLookClient())
{
SvnLookOrigin o = new SvnLookOrigin(path);
Collection<SvnChangedEventArgs> changeList;
client.GetStatus(o, out changeList); // Should now return the differences between this working copy and the remote status.
}