I can create blog post in confluence using the script below:
import sys
from xmlrpclib import Server
user = "user"
passwd = "pass"
serverurl = "<blah-blah>/xmlrpc"
spacekey = "DEV"
s = Server( serverurl )
token = s.confluence1.login( user, passwd )
newblogpostdata = {"title":"title",
"content":"content",
"space":spacekey}
newblogpostdata = s.confluence1.storeBlogEntry(token, newblogpostdata)
But couldn't find how to add some labels to the blog post?
Update. Finally I used the following solution:
id = newblogpost['id']
s.confluence1.addLabelByName(token, "ctrm", id)
Have you tried using macros in your content?
https://confluence.atlassian.com/display/DOC/Using+Label+Macros+to+Categorise+Wiki+Content
https://confluence.atlassian.com/display/DOC/Confluence+Wiki+Markup+for+Macros
But you would have to experiment to find proper syntax I am afraid.
Related
I am trying to write a python script to validate if a username exists in a particular domain or not .
To query :
username -- > anandabhis
domain name --> example.com
Output : Successfully verified .
For this I have used python-ldap module to connect to LDAP server . But I am unable to proceed further even after reading lots of documentations.
import ldap
def test_login(self):
domain = 'EXAMPLE'
server = 'ldap-001.example.com'
admin_username = 'admin'
admin_password = 'secret-password'
connection = ldap.initialize('ldap://{0}'.format(server))
connection.protocol_version = 3
connection.set_option(ldap.OPT_REFERRALS, 0)
connection.simple_bind_s('{0}\{1}'.format(domain, admin_username), admin_password)
search_username = 'anandabhis'
A simple search for the sAMAccountName of the user should allow you to get the attributes of the user.
user_filter = '(sAMAccountName={})'.format(search_username)
base_dn = 'DC={},DC=com'.format(domain)
result = connection.search_s(base_dn, ldap.SCOPE_SUBTREE, user_filter)
print result
I am trying to create a script using python and REST to get data from JIRA,currently am able to get data for each JIRA ticket using the code shown below,I want to be able to write queries to retrieve large data which I do currently from the UI as shown below,how can I update my current script to achieve this from the script?
Query:
"project = ITTICKETS AND "Build Info" ~ CI_-STD.INT-2"
Python code:-
import requests
import json
import logging
import datetime
import base64
serverURL = 'https://jira.company.com/jira'
user = 'username'
password = 'password'
jql = '/rest/api/2/issue/JIRATICKET-152133'
response = requests.get(serverURL + jql,verify=False,auth=(user, password))
print response
#print response.data
print response.json()
Try setting jql like this:
import urllib
query = 'project = ITTICKETS AND "Build Info" ~ CI_-STD.INT-2'
jql = '/rest/api/2/search?jql=%s' % urllib.quote(query)
I am using python wordpress_xmlrpc library for extracting wordpress blog data. I want to fetch all posts of my wordpress blog. This is my code
client = Client(url, 'user', 'passw')
all_posts = client.call(GetPosts())
But this is returning only the latest 10 posts. Is there any way to get all the posts?
This is how I do it :
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts
from wordpress_xmlrpc import WordPressTerm
from wordpress_xmlrpc.methods import posts
client = Client('site/xmlrpc.php', 'user', 'pass')
data = []
offset = 0
increment = 20
while True:
wp_posts = client.call(posts.GetPosts({'number': increment, 'offset': offset}))
if len(wp_posts) == 0:
break # no more posts returned
for post in wp_posts:
print(post.title)
data.append(post.title)
offset = offset + increment
According to the documentation, you can pass a parameter indicating how many posts you want to retrieve as:
client.call(GetPosts({'number': 100}))
Alternatively, if you want to get all the posts, check this out: https://python-wordpress-xmlrpc.readthedocs.org/en/latest/examples/posts.html#result-paging
I have been getting this error trying to print my friends list for awhile. I am fairly certain I am providing a token. Any idea's on this?
import facebook
import urllib
import urllib2
import json
import urlparse
import subprocess
import warnings
import urllib2
import json
#https://developers.facebook.com/tools/access_token/
# Parameters of your app and the id of the profile you want to mess with.
FACEBOOK_APP_ID = '{app_id}'
FACEBOOK_APP_SECRET = '{app_secret}'
FACEBOOK_PROFILE_ID = 'my-id-number-here'
# Trying to get an access token. Very awkward.
oauth_args = dict(client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_APP_SECRET,
grant_type = 'client_credentials')
oauth_curl_cmd = ['curl',
'https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(oauth_args)]
oauth_response = subprocess.Popen(oauth_curl_cmd,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE).communicate()[0]
try:
oauth_access_token = urlparse.parse_qs(str(oauth_response))['access_token'][0]
except KeyError:
print('Unable to grab an access token!')
exit()
facebook_graph = facebook.GraphAPI(oauth_access_token)
# Print friends list.
profile = facebook_graph.get_object("me")
friends = facebook_graph.get_connections("me", "friends")
friend_list = [friend['name'] for friend in friends['data']]
print friend_list
You are getting this error cause you are using an access token not a user token.
The user token can be generated by using facebook developers
https://developers.facebook.com/tools/explorer/145634995501895/
Just click Get Token > Get User Access Token
This does the trick for me
Probably your short-lived access token has expired. You can check this via
https://developers.facebook.com/tools/debug/accesstoken/
and review the validity of the access token.
I am creating a integration tool to integrate with rally and my web application. I decided to use Python to run in my web-server to retrieve the contents from rally.
In one of the scenario, I need to get the last modified task from a story. I don't know the ID, Name or anything, but I know the story name. Using the story name, how can I get the last modified task(s)?
Here's an example of how to set up Kyle's query in pyral:
server = "rally1.rallydev.com"
user = "user#company.com"
password = "topsecret"
workspace = "My Workspace"
project = "My Project"
rally = Rally(server, user, password, workspace=workspace, project=project)
rally.enableLogging("rally.history.showtasks")
fields = "FormattedID,State,Name,WorkProduct,Name,LastUpdateDate",
criterion = 'Workproduct.Name = "My Tasks User Story"'
response = rally.get('Task', fetch=fields, query=criterion, order="LastUpdateDate Desc",pagesize=200, limit=400)
most_current_task = response.next()
print "%-8.8s %-52.52s %s" % (most_current_task.FormattedID, most_current_task.Name, most_current_task.State)
I'm not super familiar with how to use pyral but you should be able to get what you'd like by querying against the task wsapi endpoint like so:
/slm/webservice/1.40/task.js?query=(WorkProduct.Name = "Story Name")&order=LastUpdateDate DESC
Now you just need to get pyral to generate that request. :-)