I want to see the 'user(specifically, user's display_name') data using Stackoverflow's API.
I'm using and reading the docs about StackExchange API, and still didn't get the idea about 'fetch' and anything about get the data.
Using 'beautifulsoup' or any crawling code, is it the only way to get the data?
from stackapi import StackAPI
SITE = StackAPI('stackoverflow')
users = SITE.fetch('users')
print(users['items'])
Following the documentation for the StackAPI python library, the method skeleton is fetch(endpoint=None, page=1, key=None, filter='default', **kwargs).
So your api call will look something like:
from stackapi import StackAPI
SITE = StackAPI('stackoverflow')
SITE.page_size = 5 # limits to 5 returned results for demo purpose
users = SITE.fetch('users', filter='!)mYVom7)TA9')
print(users['items'])
where the filter code was obtained from the get users docs for the api.
Returns:
[{'display_name': 'Jon Skeet'}, {'display_name': 'Gordon Linoff'}, {'display_name': 'VonC'}, {'display_name': 'BalusC'}, {'display_name': 'Darin Dimitrov'}]
Related
I want to get a one product information by Id in wcapi(Module page).I use this code But dont work :/ and get all product information
from woocommerce import API
wcapi = API()
response = wcapi.get('products',params={'id':776}).json()
As other mentioned the API works as below:
/wp-json/wc/v3/products/<id>
So use the API as mentioned in the documentation and your code should be like below:
from woocommerce import API
wcapi = API()
response = wcapi.get("products/794").json()
Read more about the output here.
It's always a good idea to stick with documentation.
I am not able to understand how to fetch the status of the pull request via Python jira API.
I have gone through https://jira.readthedocs.io/en/latest/examples.html,
and searched the internet for it. But I was not able to link the jira issue with the pull request, I saw that the pull request is linked to jira issue id, but was not able to understand how to implement it.
I am using python 3.7
from jira import JIRA
issue = auth_jira.issue('XYZ-000')
pull_request = issue.id.pullrequest
I am getting this error:
AttributeError: 'str' object has no attribute 'pullrequest'
I am not sure how to access pullrequest data in jira.
Any leads would help.
I did something similar with another python wrapper for the jira-API: atlassian-python-api.
Look if it works in your case:
from atlassian import Jira
from pprint import pprint
import json
jira = Jira(
url='https://your.jira.url',
username=user,
password=pwd)
issue = jira.get_issue(issue_key)
# get the custom field ref of the "Development" field (I don't know if it's always the same):
dev_field_string = issue["fields"]["customfield_13900"]
# the value of this field is a huge string containing a json, that we must parse ourselves:
json_str = dev_field_string.split("devSummaryJson=")[1][:-1]
# we load it with the json module (this ensures json is converted as dict, i.e. 'true' is interpreted as 'True'...)
devSummaryJson = json.loads(json_str)
# the value of interest are under cachedValue/summary:
dev_field_dic = devSummaryJson["cachedValue"]["summary"]
pprint(dev_field_dic)
# you can now access the status of your pull requests (actually only the last one):
print(dev_field_dic['pullrequest']['overall']['state'])
I hope all you guys be fine.
I was trying to modify multiple products in Woocommerce with python(Restful Api WooCommerce)
here is the code I used:
import sys
import json
from woocommerce import API
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
wcapi = API(
url="https://...",
consumer_key="ck_...",
consumer_secret="cs_...",
wp_api = True,
version="wc/v3",
query_string_auth=True # Force Basic Authentication as query string true and using under HTTPS
)
data = {"id":"1995","regular_price":"1775000","sale_price":"1685000","stock_quantity":"6"},
{"id":"4673","regular_price":"2300000","sale_price":"2045000","stock_quantity":"15"}
print(wcapi.put("products/bulk",data).json())
but when I run the code, I got below error:
{'code': 'rest_no_route', 'message': 'No route was found matching the URL and request method', 'data': {'status': 404}}
product IDs are available.
before trying to make some changes on bulk, I was able to modify a single product with the below code:
print(wcapi.put("products/1995",data).json())
my current Woocommerce version 3.9 - & - current python version 3.8.1
i was not able to find the solution or why is that happening. how to fix it?
also how can i modify multiple variable Woocommerce products?
Thanks
finally, the problem got solved.
I just wanted to post it here for the future use of others who may face such this problem.
here is the change which I made in the code:
data = {
"update":
[
{
"id":"1995",
"regular_price":"1775000",
"sale_price":"1685000",
"stock_quantity":"6"},
{
"id":"4673",
"regular_price":"2300000",
"sale_price":"2045000",
"stock_quantity":"15"}
]
}
# Bulk edit of Woocommerce products - here we have 2 sample products
print(wcapi.put("products/batch",data).json())
if you have a better way or think should notice any other thing for working with woocommerce in python, happy to have your post below in this post:-)
I am very new to the Graph API and a basically trying to write a python (v2.7) script which takes as input the userID of a Facebook user and returns names/IDs of all groups/pages that have been liked by the user.
I have managed to acquire an Access Token that uses the following permissions: user_likes and user_groups. Do I need anything else?
I have used the following code so far to get a JSON dump of all the output from this access token:
import urllib
import json
import sys
import os
accessToken = 'ACCESS_ToKEN_HERE' #INSERT YOUR ACCESS TOKEN
userId = sys.argv[1]
limit=100
# Read my likes as a json object
url='https://graph.facebook.com/'+userId+'/feed?access_token='+accessToken +'&limit='+str(limit)
data = json.load(urllib.urlopen(url))
id=0
print str(data)
I did get some JSON data but I couldn't find any page/group related info in it neither did it seem to be the most recently updated data! Why is this?
Also, what are the field names that must be tracked to detect a page or a group in the likes data? Please help!
You are using the wrong API- /feed - this will fetch the feeds/posts of the user, not the pages/groups.
To get the groups he has joined:
API: /{user-id}/groups
Permissions req: user_groups
To get the pages he has liked:
API: /{user-id}/likes
Permissions req: user_likes
I am trying to do batch searching and go over a list of strings and print the first address that google search returns:
#!/usr/bin/python
import json
import urllib
import time
import pandas as pd
df = pd.read_csv("test.csv")
saved_column = df.Name #you can also use df['column_name']
for name in saved_column:
query = urllib.urlencode({'q': name})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
search_response = urllib.urlopen(url)
search_results = search_response.read()
results = json.loads(search_results)
data = results['responseData']
address = data[u'results'][0][u'url']
print address
I get a 403 error from the server:
'Suspected Terms of Service Abuse. Please see http://code.google.com/apis/errors', u'responseStatus': 403
Is what I'm doing is not allowed according to google's terms of service?
I also tried to put time.sleep(5) in the loop but I get the same error.
Thank you in advance
Not allowed by Google TOS. You really can't scrape google without them getting angry. It's also a pretty sophisticated blocker, so you can get around for a little while with random delays, but it fails pretty quickly.
Sorry, you're out of luck on this one.
https://developers.google.com/errors/?csw=1
The Google Search and Language APIs shown to the right have been officially deprecated.
Also
We received automated requests, such as scraping and prefetching. Automated requests are prohibited; all requests must be made as a result of an end-user action.