Sharepoint Query returns no results for with >5000 items - sharepoint

When I go to a specific folder in Sharepoint, I hit an error that I have exceeded the view threshold of 5000 items. I created a new view to only show items when the ID < 5000, I am able to see the folder contents now.
However, how do I apply a specific view/filter when using Python?
Using Python's request module, I have:
requestUrl = sharePointUrl + "/{0}/_api/web/GetFolderByServerRelativeUrl('/{0}/{1}')/Files".format(site, folder)
headers={'Content-Type': 'application/json; odata=verbose', 'accept': 'application/json;odata=verbose'}
requests.get(requestUrl , headers=headers).json()
which returns {'d': {'results': []}}
If I modify the requestUrl to include ?$top=1000 or ?$filter=Id lt 1000, I still have an empty result (no throttled error, just empty result)
How do I apply the filters correctly or use a specific view when running the request query?
(I used a different folder name and I get an error 'Field or property "Id" does not exist.' so clearly something is wrong with my query too but I am not sure why the other folder returns empty result and not an error)

just having a first glance on it and looking at this line
requestUrl = sharePointUrl + "/{0}/_api/web/GetFolderByServerRelativeUrl('/{0}/{1}')/Files".format(site, folder)
it will seem like the URL you want to create might be wrong. I think you should not add site to the GetFolderByServerRelativeUrl as you already will be running this in the context of the site. So for example if your site is sites/someSite and folder is shared documents you will have
sites/someSite/_api/web/GetFolderByServerRelativeUrl('/sites/someSite/shared documents')/Files
but I think you should have something like
sites/someSite/_api/web/GetFolderByServerRelativeUrl('shared documents')/Files
could you give it a double check?

Related

Why do I fail to submit data to textarea with python requests.post()

I want to use the requests.post tool to automatically query domain name attribution on this websitea website,But the return value is always empty, I guess it is because the post method failed to transfer the data to the textarea
url = 'http://icp.chinaz.com/searchs'
data = {
'hosts':'qq.com',
'btn_search':'%E6%9F%A5%E8%AF%A2', '__RequestVerificationToken=':'CfDJ8KmGV0zny1FLtrcRZkGCczG2owvCRigVmimqp33mw5t861kI7zU2VfQBri65hIwu_4VXbmtqImMmTeZzqxE7NwwvAtwWcZSMnk6UDuzP3Ymzh9YrHPJkj_cy8vSLXvUYXrFO0HnCb0pSweHIL9pkReY',
}
requests.post(url=url,data=data,headers=headers).content.decode('utf-8')
I'd be very grateful if you could point out where I'm going wrong
I have tried to replace headers and so on.

Kodi addons : how to correctly set an URL using xbmcplugin.addDirectoryItems and xbmcgui.ListItem?

I'm trying to update a plugin for Kodi 19 (and Python3).
But! Hell! Their documentation is a mess, and when you search the internet, a lot of code is outdated.
I cannot understand how correctly create a virtual folder with items using xbmcplugin.addDirectoryItems.
here's my (simplified) code:
this is my KODI menu function
def menu_live():
#this is were I get my datas (from internet)
datas = api.get_live_videos()
listing = datas_to_list(datas)
sortable_by = (xbmcplugin.SORT_METHOD_DATE,
xbmcplugin.SORT_METHOD_DURATION)
xbmcplugin.addDirectoryItems(common.plugin.handle, listing, len(listing))
xbmcplugin.addSortMethod(common.plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.endOfDirectory(common.plugin.handle)
this builds a list of items for the virtual folder
def datas_to_list(datas):
list_items = []
if datas and len(datas):
for data in datas:
li = data_to_listitem(data)
url = li.getPath()
list_items.append((url, li, True))
return list_items
this create a xbmcgui.ListItem for our listing
def data_to_listitem(data):
#here I parse my data to build a xbmcgui.ListItem
label = ...
url = ...
...
list_item = xbmcgui.ListItem(label)
list_item.setPath(url)
return list_item
I don't understand well how to interact with the media url.
It seems that it can be defined within xbmcgui.ListItem using
list_item.setPath(url)
which seems ok to me (an url is set to the item itself)
but then, it seems that you also need to set the URL when adding the item to the list,
li = data_to_listitem(data)
list_items.append((url, li, True))
This looks weird since it means you have to know the URL outside the function that builds the item.
So currently, my workaround is
li = data_to_listitem(data)
url = li.getPath() #I retrieve the URL defined in the above function
list_items.append((url, li, True))
That code works. But the question is: if I can define an URL on the ListItem using setPath(), then why should I also fill that URL when appending the ListItem to my listing list_items.append((url, li, True)) ?
Thanks a lot !
I'm not exactly sure what your question is. But Video/audio add-on development is thoroughly explained in these guides: https://kodi.wiki/view/HOW-TO:Audio_addon, https://kodi.wiki/view/Audio-video_add-on_tutorial and https://kodi.wiki/view/HOW-TO:Video_addon. Have a look at them, especially the video-add-on guide (as pointed out by Roman), and try to adapt to your case.
Edit
But the question is: if I can define an URL on the ListItem using setPath(), then why should I also fill that URL when appending the
ListItem to my listing?
I'm far from an expert, but from my understanding and in the context of https://kodi.wiki/view/HOW-TO:Video_addon tutorial, the url in
list_items.append((url, li, is_folder))
is used to route your plugin to your playback function, as well as passing arguments to it (e.g. video url and possibly other useful stuff needed for playback). That is, the list item passed here doesn't need to have its path set.
ListItem.setPath(video_url)
on the other hand, is for resolving the video url and start the playback after you have selected an item.

Insert values into API request dynamically?

I have an API request I'm writing to query OpenWeatherMap's API to get weather data. I am using a city_id number to submit a request for a unique place in the world. A successful API query looks like this:
r = requests.get('http://api.openweathermap.org/data/2.5/group?APPID=333de4e909a5ffe9bfa46f0f89cad105&id=4456703&units=imperial')
The key part of this is 4456703, which is a unique city_ID
I want the user to choose a few cities, which then I'll look through a JSON file for the city_ID, then supply the city_ID to the API request.
I can add multiple city_ID's by hard coding. I can also add city_IDs as variables. But what I can't figure out is if users choose a random number of cities (could be up to 20), how can I insert this into the API request. I've tried adding lists and tuples via several iterations of something like...
#assume the user already chose 3 cities, city_ids are below
city_ids = [763942, 539671, 334596]
r = requests.get(f'http://api.openweathermap.org/data/2.5/groupAPPID=333de4e909a5ffe9bfa46f0f89cad105&id={city_ids}&units=imperial')
Maybe a list is not the right data type to use?
Successful code would look something like...
r = requests.get(f'http://api.openweathermap.org/data/2.5/group?APPID=333de4e909a5ffe9bfa46f0f89cad105&id={city_id1},{city_id2},{city_id3}&units=imperial')
Except, as I stated previously, the user could choose 3 cities or 10 so that part would have to be updated dynamically.
you can use some string methods and list comprehensions to append all the variables of a list to single string and format that to the API string as following:
city_ids_list = [763942, 539671, 334596]
city_ids_string = ','.join([str(city) for city in city_ids_list]) # Would output "763942,539671,334596"
r = requests.get('http://api.openweathermap.org/data/2.5/group?APPID=333de4e909a5ffe9bfa46f0f89cad105&id={city_ids}&units=imperial'.format(city_ids=city_ids_string))
hope it helps,
good luck

how do we add url parameters? (EJS + Node + Express)

I understood how we parse the url parameters in express routes, as in the example
How to get GET (query string) variables in Express.js on Node.js?
But where do the url parameters come from in the first place?
EDIT:
Apparently, I can build such a query with jquery (i.e $.get). I can append params to this query object. It s cool, but still i m trying to understand how we achieve this in the query that renders the page as a whole.
An example : when i choose the oldest tab below, how does SO add ?answertab=oldest to the url so it becomes :
https://stackoverflow.com/questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top
The string you're looking at is a serialization of the values of a form, or some other such method of inputing data. To get a sense of this, have a look at jQuery's built in .serialize() method.
You can construct that string manually as well, and that's pretty straight forward as well. The format is just ?var1=data1&var2=data2 etc. If you have a JSON object {"name": "Tim", "age": 22} then you could write a very simple function to serialize this object:
function serializeObject(obj) {
var str = "?";
for(var i = 0; i < Object.keys(obj).length; i++) {
key = Object.keys(obj)[i];
if (i === Object.keys(obj).length - 1)
str += encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]);
else
str += encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]) + "&";
}
return str;
}
Running seralizeObject({"name": "Tim", "age": 22}) will output '?name=Tim&age=22'. This could be used to generate a link or whatnot.
The page author writes them so. This is how they "come in the first place". The authors of an HTML page decide (or are told by website designers) where to take the user when he clicks on a particular anchor element on it. If they want users to GET a page with some query parameters (which their server handles), they simply add query string of their choice to the link's href attribute.
Take a look at the href attribute of the oldest tab you clicked:
<a
class="youarehere"
href="/questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top"
title="Answers in the order they were provided"
>
oldest
</a>
When you clicked it, the browser simply took you to path indicated in href attribute /questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top relative to the base URL http://stackoverflow.com. So the address bar changed.
stackoverflow.com may have its own system of generating dynamic HTML pages. Their administrators and page authors have configured their server to handle particular query parameters and have put in place their own methods to make sure that links on their pages point to the URL(including query string) they wish.
You need to provide URIs with query strings of your choice (you can build them using url.format and querystring.stringify) to your template system to render. Then make your express routes process them and generate pages depending on their value.

SharePoint 2007, how to check if a folder exists in a document library

I am accessing SharePoint via its web services... Which are a bit limited, as a result I have turned to WebDav to perform some create folder functionality...
I have a document library, and I am about to create a folder using webdav, but I can't find any documentation on the internet or anywhere else on how to check if a folder already exists using webdav, so is there a way to check if a folder exists in a document library in SharePoint, any hack and slash methods welcome!
Somehow, I don't get your question. First sentence states you are using web service (I'd normally understand it as the SOAP web services provided by SharePoint). The next one says you are using WebDAV which is a completely different protocol.
So, WebDAV is the protocol "Windows Explorer" uses to access SharePoint, if you open it it "Explorer mode". Since all these requests are actually HTTP requests, you can spy on them, using the "Fiddler" tool.
I believe, before opening a folder, Windows Explorer tries to query sharepoint, if such folder exists. If I try to open an unexistant path \\mysrv\sites\myweb\mylib\notthere (but \\mysrv\sites\myweb\mylib is an existing document library!) thru windows explorer, the last HTTP call I see is:
PROPFIND /sites/myweb/mylib HTTP/1.1
User-Agent: Microsoft-WebDAV-MiniRedir/6.1.7600
Depth: 1
translate: f
Where SharePoint responds with: a list of subfolders and pages in this folder (very long XML, but it contains items like this):
<D:multistatus
xmlns:D="DAV:"
xmlns:Office="urn:schemas-microsoft-com:office:office"
xmlns:Repl="http://schemas.microsoft.com/repl/"
xmlns:Z="urn:schemas-microsoft-com:">
<D:response>
<D:href>http://sites/myweb/mylib</D:href>
<D:propstat>
<D:prop>
<D:displayname>mylib</D:displayname>
<D:lockdiscovery/>
<D:supportedlock/>
<D:isFolder>t</D:isFolder>
<D:iscollection>1</D:iscollection>
<D:ishidden>0</D:ishidden>
<D:getcontenttype>application/octet-stream</D:getcontenttype>
<D:getcontentlength>0</D:getcontentlength>
<D:resourcetype>
<D:collection/>
</D:resourcetype>
<Repl:authoritative-directory>t</Repl:authoritative-directory>
<D:getlastmodified>2009-12-07T09:07:19Z</D:getlastmodified>
<D:creationdate>2009-11-06T13:30:26Z</D:creationdate>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
<!---List of other <D:response> elements -->
</D:multistatus>
If the contained element is a folder, it must have "D:isFolder" value "t". This way you can find, if the parent folder contains the folder you are going to create.
EDIT: created a small c# sample which first reads the result stream and then parses the result a bit. You need to make it better, to see if the list contains the folders you need or not.
System.Net.HttpWebRequest oReq;
string sUrl = "http://yoursite/sites/somesite/DocumentLibrary";
oReq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(sUrl);
oReq.Method = "PROPFIND";
oReq.Credentials = System.Net.CredentialCache.DefaultCredentials;
oReq.AllowAutoRedirect = true;
oReq.UserAgent = "Microsoft-WebDAV-MiniRedir/6.1.7600";
//this causes all of the items to be enumerated,
//if it is 0, only the folder itself is returned in the response
oReq.Headers["Depth"] = "1";
oReq.Headers["translate"] = "f";
System.IO.StreamWriter oRequest =
new System.IO.StreamWriter(oReq.GetRequestStream());
oRequest.WriteLine();
oRequest.Close();
System.IO.StreamReader oResponse =
new System.IO.StreamReader(oReq.GetResponse().GetResponseStream());
string sResponse = oResponse.ReadToEnd();
oResponse.Close();
//done with the webclient stuff, check the results
System.Xml.XmlDocument oMyDoc = new System.Xml.XmlDocument();
oMyDoc.LoadXml(sResponse);
System.Xml.XmlNamespaceManager oNsMgr =
new System.Xml.XmlNamespaceManager(oMyDoc.NameTable);
oNsMgr.AddNamespace("D", "DAV:");
System.Xml.XmlNodeList oAllResponses =
oMyDoc.SelectNodes(".//D:multistatus/D:response", oNsMgr);
foreach (System.Xml.XmlNode oNode in oAllResponses)
{
Console.WriteLine("Name: " +
oNode.SelectSingleNode("./D:propstat/D:prop/D:displayname",
oNsMgr).InnerText);
if (oNode.SelectNodes("./D:propstat/D:prop/D:isFolder", oNsMgr).Count > 0)
{
Console.WriteLine("Is folder: " +
oNode.SelectSingleNode("./D:propstat/D:prop/D:isFolder",
oNsMgr).InnerText);
}
else
{
Console.WriteLine("Is folder: f");
}
Console.WriteLine();
}
YOu don;t need to, if it already exists, trying to create a new folder with that name will "silently" return the already existing folder.

Resources