i want to mass follow twitter accounts but i got error that said i've requested to follow - twitterapi-python

So i want to mass follow people on Twitter with my account
but im kinda confused because i don't know how to fix the error, like i've requested to follow the "user", so what i want to do is skip the user if ive requested to follow them, but i dont know how to fix it, here's the code
`
following = api.get_friend_ids(screen_name = "2Wild2Crazy")
friends = api.get_friends(screen_name = "2Wild2Crazy", count = 200)
for i in range(len(friends)):
print(""" " """, friends[i].screen_name, """ " """)
#mass follow the people who follow 2Wild2Crazy
for i in range(len(friends)):
api.create_friendship(screen_name = friends[i].screen_name)
`

Just do
#mass follow the people who follow 2Wild2Crazy
for i in range(len(friends)):
try:
api.create_friendship(screen_name = friends[i].screen_name)
except tweepy.errors.Forbidden:
print("Already following user: {}, skipping.".format(friends[i].screen_name))
Might have to import tweepy to be able to except the error. If you don't like the print command you can replace it with pass that will tell python to just ignore that specific error.

Related

Moodle - update_moduleinfo - invalid course module id

I'm currently building a new moodle plugin. I'm using add_moduleinfo and update_moduleinfo. To add a new attandance atictivity in a course and update it later on.
Sadly I'm facing the issue that update_moduleinfo always throws an "invalid course module id" error. I already checked the cm entry in my database to ensure im using the right module instance.
I dont really know what to do.
$cm = get_coursemodule_from_instance($moduleName, $activityID, $course->id);
$moduleinfo = update_moduleinfo($cm, $moduleinfo, $course); <-- Error
Thats how I try to update the entry.
I also found that post. Didn't help anything.
Moodle - Invalid course module ID
I found the issue myself:
$moduleinfo->introeditor['format'] = FORMAT_HTML;
$moduleinfo->introeditor['text'] = "INTRO TEXT";
$moduleinfo->coursemodule = $cm->id;
list($cm, $moduleinfo) = update_moduleinfo($cm, $moduleinfo, $course, null);
In order to use this function the above mentioned properties need to exist in order to perform a update.

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.

Export Standard/Extended User Greetings (Exchange 2016) - For Use In XMedius AVST

In an earlier post on June 18, 2018 (my birthday BTW), a user asked "Hopefully a simple question - at one time I know when user's recorded their personal greetings for UM voicemail in o365 (regular greeting and/or extended absence greeting) these were stored in their Exchange inbox using a special item type (i.e. "IPM.Configuration.Um.CustomGreetings.External"). However setting up my test o365 setup, getting UM configured and all that, after recording my personal greeting and going through each item starting from the root of my inbox, (some 900+ items - lots of odd stuff in there) - I don't see anything like this any more. Lots of log, activity items, some messages but nothing about greetings. Extracting everything that could cast to an email type to a folder I went through each one - nothing promising. anyone have any clues where the custom greetings for users UM (not auto attendant recordings - that's a different beast) has gone off to and how to get to it?" After reading through the answers as well as the code that was provided by Jeff Lindborg, I thought that I was getting somewhere. With a lot of trial and error, I was finally able to get the EWS-FAI module installed as well as the Exchange Web Services API. Unfortunately, when it came to running the provided code, this is where I am stumped. I'm not a developer or 'coder' in any form, but I'm always looking for effective and efficient methods to do my work. With that said, I'm trying to run this on a Win10 workstation, but can't seem to figure out which program this needs to run within. I've tried Powershell, but that doesn't work. I have access to the necessary accounts for mailbox impersonation as well as any other permissions needed. I've provided the code that was originally supplied for review. Any additional help would be greatly appreciated.
Code
ExchangeService _service;
_service = new ExchangeService(ExchangeVersion.Exchange2016); // Exchange2013_SP1);
_service.Credentials = new WebCredentials("user#domain", "myPw");
_service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
//select the user you're fetching greetings for
_service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "user#domain");
//get the root folder for the current account
var oParamList = new List<FolderId> {WellKnownFolderName.Root};
var oTemp = _service.BindToFolders(oParamList, PropertySet.FirstClassProperties);
var oRoot = oTemp.First().Folder;
var oView = new ItemView(50)
{
PropertySet = new PropertySet(BasePropertySet.FirstClassProperties),
Traversal = ItemTraversal.Associated
};
SearchFilter oGreetingFilter = new SearchFilter.ContainsSubstring(ItemSchema.ItemClass,
"IPM.Configuration.Um.CustomGreetings", ContainmentMode.Substring, ComparisonMode.IgnoreCase);
var oResults = _service.FindItems(oRoot.Id, oGreetingFilter, oView);
//fetch the binary for the greetings as values
var oPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
var oRoamingBinary = new ExtendedPropertyDefinition(31753, MapiPropertyType.Binary);
oPropSet.Add(oRoamingBinary);
_service.LoadPropertiesForItems(oResults, oPropSet);
var strFileName = "";
foreach (var oItem in oResults.Items)
{
if (oItem.ItemClass.Equals("IPM.Configuration.Um.CustomGreetings.External",
StringComparison.InvariantCultureIgnoreCase))
strFileName = "jlindborg_Standard.wav";
if (oItem.ItemClass.Equals("IPM.Configuration.Um.CustomGreetings.Oof",
StringComparison.InvariantCultureIgnoreCase))
strFileName = "jlindborg_Extended.wav";
File.WriteAllBytes("d:\\" + strFileName, (byte[]) oItem.ExtendedProperties.First().Value);
}
}
The code you posted is c# so you would need to use Visual Studio to create a C# application add a reference to the EWS Managed API and compile that for it to work (you'll need to engage a developer or learn some basic coding).
EWS-FAI is a powershell module it should be able to return that item and you should be able to write that to a file eg something like
$MailboxName = "mailbox#domain.com"
$Item = Get-FAIItem -MailboxName $MailboxName -ConfigItemName Um.CustomGreetings.External -Folder Inbox -ReturnConfigObject
[System.IO.File]::WriteAllBytes(("C:\temp\" + $MailboxName + ".wav"),$Item.BinaryData)

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)

Redmine REST API called from Ruby is ignoring updates to some fields

I have some code which was working at one point but no longer works, which strongly suggests that the redmine configuration is involved somehow (I'm not the redmine admin), but the lack of any error messages makes it hard to determine what is wrong. Here is the code:
#!/usr/bin/env ruby
require "rubygems"
gem "activeresource", "2.3.14"
require "active_resource"
class Issue < ActiveResource::Base
self.site = "https://redmine.mydomain.com/"
end
Issue.user = "myname"
Issue.password = "mypassword" # Don't hard-code real passwords :-)
issue = Issue.find 19342 # Created manually to avoid messing up real tickets.
field = issue.custom_fields.select { |x| x.name == "Release Number" }.first
issue.notes = "Testing at #{Time.now}"
issue.custom_field_values = { field.id => "Release-1.2.3" }
success = issue.save
puts "field.id: #{field.id}"
puts "success: #{success}"
puts "errors: #{issue.errors.full_messages}"
When this runs, the output is:
field.id: 40
success: true
errors: []
So far so good, except that when I go back to the GUI and look at this ticket, the "notes" part is updated correctly but the custom field is unchanged. I did put some tracing in the ActiveRecord code and that appears to be sending out my desired updates, so I suspect the problem is on the server side.
BTW if you know of any good collections of examples of accessing Redmine from Ruby using the REST API that would be really helpful too. I may just be looking in the wrong places, but all I've found are a few trivial ones that are just enough to whet one's appetite for more, and the docs I've seen on the redmine site don't even list all the available fields. (Ideally, it would be nice if the examples also specified which version of redmine they work with.)