how to add a buddy to buddy list in twisted.words oscar (icq) - twisted

I've got a small bot communicating with users on ICQ, it's using Twisted.Words, Oscar protocol. I need to see their online status, but that seems to be only possible when I have them in my buddy list. So here comes the question:
How do I add a buddy to my buddy list in Twisted.Words Oscar?
That's pretty weird, but there seems to be nothing about it in the API docs and I couldn't find any good clues in the oscar.py source code. :\

Finally I came up with a solution, after hours of looking at the code of oscar.py and at OSCAR protocol documentation.
So here we go. Go to the function gotBuddyList(self, l) in this example:
http://twistedmatrix.com/documents/current/words/examples/oscardemo.py
You might have your own analogue, that's a callback function called when the SSI is received. It's bound like this:
self.requestSSI().addCallback(self.gotBuddyList)
So inside this gotBuddyList(self, l) function you put this:
self.groupAll = l[0][0]
In my case, this contains the first buddy group in my buddy list (which was created manually in advance, from a regular ICQ client). The l variable is the SSI received from the server and it contains your buddy groups, buddies in those groups and other stuff like settings or something. That's according to the OSCAR docs.
I'm going to add my buddies to the first group in my list. If you have your own cases or want to create a more flexible solution, you'll have to make more investigation on that.
Next, when you want to add a new buddy to your buddy list, you do this (assuming this is still inside one of your BOSConnection's implementation class methods):
buddy = oscar.SSIBuddy(the_uin_to_add) # put the UIN of the buddy to add in the argument
try:
buddyID = max(self.groupAll.usersToID.itervalues()) + 1 # incrementing the buddyID
except ValueError: # if the group is empty yet
buddyID = 1
self.groupAll.addUser(buddyID, buddy) # adding it to the group
self.addItemSSI(buddy) # actually sending the stuff to the server
And here you are, the buddy is in your list now. If he's online, you'll immediately get an updateBuddy event, containing the info about his online status and so on.
Here I couldn't really understand what the buddyID is. There's no info explaining it. But I finally assumed that it's just an inner ID inside the group the buddy is in. It's limited by 32767. I decided to go from 1 and increment it by one from the highest in the group each time.
That's all I have. I hope it can help someone once. If you can add anything or correct me, I'll be glad to see your comments!

Related

Show content based on whether the user has certain tag in Mailchimp

I went through the Merge Tags here and here, but couldn't figure out the syntax that would allow me to show content based on whether the user has certain Tag or not.
Help?
My goal in case it helps:
User subscribes, and is queued for a welcome mail one day later. In meantime that user may get tagged (my way of segmenting them), and so, the next day when that user receives the welcome mail, the content needs to be catered based on the tag that user got.
Got a response from their support saying
merge tags do not work with Tags just yet
here's the whole thing:
While we do have conditional merge tags available, I'm afraid we do
not have any that would work with Tags. To be transparent, Tags were
recently added a few months ago, and there are some features in our
application that has not updated to work with Tags just yet.
Because conditional merge tags do not work with tags yet, the best
option would be to create multiple automations and send them out based
on each tags. If you do it that way, you'll be able to target those in
specific tags with specific content
Dug a little deeper from the first link. There is another link Use Conditional Merge Tag Blocks which contained the below code:
Name
IF-ELSE
Definition
Use ELSE to indicate alternative content to display if the *|MERGE|* tag value is false.
Example
*|IF:MERGE|* content to display *|ELSE:|* alternative content to display *|END:IF|*
Name
ELSEIF
Definition
Use ELSEIF to specify a new *|MERGE|* tag to be matched against if the first *|MERGE|* tag value is false.
Example
*|IF:TRANSACTIONS >= 20|* Enjoy this 40% off coupon! *|COUPON40|*
*|ELSEIF:TRANSACTIONS >= 10|* Enjoy this 20% off coupon! *|COUPON20|*
*|ELSE:|* Enjoy this 10% off coupon! *|COUPON10|* *|END:IF|*
More examples with definitions can be found here.
Hope this is the answer you were after.

Is there a plugin that will add my name and date to the top of my files as a comment for Atom?

Most of the work I do is for school which means I need to have my name, the date, the name of the assignment, and other stuff in a comment at the top of each file I edit. Does Atom have any good plug-ins for this?
The following seem to be close to what you're looking for. You can customize the inserted templates:
https://atom.io/packages/auto-copyright
https://atom.io/packages/auto-header
Not sure whether they provide all of the fields you're looking for, but they look like a good starting point.

Middleman Blog: How do I get a count of articles?

I'm trying to return a string of the total count of items in a Middleman blog. (I'm currently using 3 on a site).
The closest I've come to getting the count is including = i in a loop, in which the results went from 0 to 34. So I know one particular blog has 35 items but I can't get that value on its own.
It feels like I should be able to do something like:
def get_articles_count(blogName)
data.blog(blogName).articles.count
end
= get_articles_count('posts')
Bonus begging: I'd love to know how I could've tracked down the answer, if possible. I'm missing something and I'd love to know where I should be looking. I've been referencing the local sitemap data http://localhost:4567/__middleman/sitemap, the MM docs, and the MM blog docs, but I can't decipher if an item in a blog is a page or an article. I only use article in my example because that's what the loops require for displaying post information.
It turns out that it's incredibly simple
= blog.articles.count
It turns out that it's so simple...
= blog.articles.count

What are the Aweber API Variables $account_id and $list_id?

You can check here:
https://labs.aweber.com/docs/code_samples/subs/create
The script to add a new subscriber to the list via api requires those two pieces info...only I cannot figure out for the life of me what those two variables are!! I've beaten through every little aspect of my Aweber Subscriber Account, AND my Aweber Labs account...and I can't find any reference to either of those variables anywhere. I've submitted some tickets to them, and haven't gotten any response yet.
Does anyone have any ideas here? I've tried my account names, my list names, to no avail!
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Okay, I've got it! You can get the values of both of these variables by dumping some other variables in the aweber api after making certain api calls.
get the account id first:
$account = $aweber->getAccount($accessKey, $accessSecret);
then vardump or print_r $account.
next we get the list id:
$account = $aweber->getAccount($accessKey, $accessSecret);
$list_url = 'https://api.aweber.com/1.0/accounts/<id>/lists';
$lists = $account->loadFromUrl($list_url);
then vardump or print_r $lists.
And you are all set! I'm so happy I figured this out, it freakin took long enough. Hopefully this saves some one a bit of time.
I too have agonized over finding the $list_ID, so went to deactivate the list, and create a new one, and "discovered" that if you hover over the Deactivate button, you get a url you can copy, and this gives both %account and %list Ids
https://www.aweber.com/users/lists/deactivate/$accountID/$lisID
like this....
https://www.aweber.com/users/lists/deactivate/123456/123456
Hopefully this will help make someone as it is a super easy solution
The proper answer is Anne Allen's one, but...
Check the return of the /accounts endpoint. It should return the same account id as you detected in the link, but I had cases they were different (strange, isn't it?). Use the account id returned by the /accounts endpoint and other endpoints to retrieve lists, subscribers, etc. will start to work. It's like if some accounts have two ids, one partially works and the other fully works.
Let me tell you how to get $list_id value... login into your AWeber account and then create a new list copy only integer value from list's name.
At first, login.
1) click Reports>Settings. Your account ID will be displayed in the box,example: ?id=XXXXX
2) click List Options>List Settings. There you will see the list ID under the name.
p.s. To add subscriber, you can use this - Automatically add into aweber list

Logging Application Block-Microsoft Enterprise Library 4.1

In Logging Application Block in Logger.Write it takes event id as one of the parameter which is integer.So how to decide what should be passed as event id?
btw, do you really need to use the eventId? I think you can just pass the string you want to log:-
Logger.Write("SomeMessage");
EDIT :- I meant there should be another overload which takes just the string you want to write.
EDIT :- From here :-
EventId - a value you can use to
further categorise Log Entries
(defaults to 0 for a LogEntry and to 1
for a LogEntry implicitly created by
Logger.Write);
What we do is gather the different "stories" that you want to report on and then assign a sequence of event IDs to each of those stories. So in short, come up with a system that works for you and document it for future reference.