How to get video links from subfolders in vimeo API? - vimeo-api

I am trying vimeo API using python in a jupyter notebook.
I want to access the links of videos located inside subfolders of a parent folder.
I can get the links of all my videos with GET /me/videos?fields=link... but if I try setting the parent folder in the uri I don't get any video (since in that folder there are none)
I know I can use "include_subfolders" with the query parameter (or if I had a tag...), but I want all the results, not to query by any particular word. I have tried querying a letter and I get some of the videos, but never all of them, and that cannot be the best solution.
Is there a way to query ALL videos inside all subfolders? I have tried with "",*, ...nothing seems to work.
Another possible solution I have thought of would be to search all the videos and filter by parent folder. With the metadata.connections.ancestor_path I get an array that I could later manipulate... but I have too many videos and I don't want them all at once, I want to get the links by folders, if possible.
Things I tried but didn't work:
In a folder with 8 subfolders and 30 video links I tried with items :
uri='https://api.vimeo.com/users/123456789/projects/3213121/items'
video_data = client.get(uri + '?fields=created_time,name,link,duration&sort=date&per_page=100&page=1').json()
Result:
{'total': 8, 'page': 1, 'per_page': 100, 'paging': {'next': None, 'previous': None, 'first': '/users/123456789/projects/3213121/items?fields=created_time%2Cname%2Clink%2Cduration&sort=date&per_page=100&page=1', 'last': '/users/123456789/projects/3213121/items?fields=created_time%2Cname%2Clink%2Cduration&sort=date&per_page=100&page=1'}, 'data': [[], [], [], [], [], [], [], []]}
Example of a query including subfolders, instead of a word, by letter:
#parent folder:
uri="https://api.vimeo.com/me/projects/12345678/videos"
video_data = client.get(uri + '?fields=created_time,name,link,duration&sort=date&per_page=100&page=1&query=A&include_subfolders=true').json()
Result: (not all the links I wanted, but some, so it should not be a problem of permisions or privacy...)
{'total': 12, 'page': 1, 'per_page': 100, 'paging': {'next': None, 'previous': None, 'first': '/me/folders/5745971/videos?fields=created_time%2Cname%2Clink%2Cduration&sort=date&per_page=100&page=1&query=A&include_subfolders=true', 'last': '/me/folders/12345678/videos?fields=created_time%2Cname%2Clink%2Cduration&sort=date&per_page=100&page=1&query=A&include_subfolders=true'}, 'data': [{'name': 'Circuito a TV', 'link': 'https://vimeo.com/12345678', 'duration': 520, 'created_time': '2021-09-22T21:38:04+00:00'}, {'name': '3 TV a Álgebra', 'link': 'https://vimeo.com/12345678', 'duration': 338, 'created_time': '2021-09-22T11:07:06+00:00'}, {'name': '2 Circuito a Álgebra', 'link': 'https://vimeo.com/12345678', 'duration': 681, 'created_time': '2021-09-22T11:06:04+00:00'}, {'name': '5 Álgebra a circuito', 'link': 'https://vimeo.com/12345678', 'duration': 267, 'created_time': '2021-09-22T11:11:34+00:00'}
This is my first question and I have searched but haven't found any question already talking about this exact issue, hope I made myself more or less clear.

Related

Create multiple (two) source with chartit in Django

I'm using chartit in a django project.
I have a models (ReadingSensor) with the following attributes:
id_sensor
date_time
value
I want to create a line chart with several lines for different id_sensors
for example:
ReadingSensor.objects.filter(id_sensor=2)
ReadingSensor.objects.filter(id_sensor=1)
For a single model we have:
ds = DataPool(
series=
[{'options': {
'source': MonthlyWeatherByCity.objects.all()},
'terms': [
'month',
'houston_temp',
'boston_temp']}
])
cht = Chart(
datasource = ds,
series_options =
[{'options':{
'type': 'line',
'stacking': False},
'terms':{
'month': [
'boston_temp',
'houston_temp']
}}],
chart_options =
{'title': {
'text': 'Weather Data of Boston and Houston'},
'xAxis': {
'title': {
'text': 'Month number'}}})
Documentation: http://chartit.shutupandship.com/docs/
I consulted the documentation but found no suggestive example to help me.
Can someone help me?
Actually the example is on the site you provide, please check this link: http://chartit.shutupandship.com/demo/chart/multi-table-same-x/
The idea is just to add more items with options and terms to the series list when constructing DataPool object and adjust the terms in series_options when constructing Chart object accordingly.
Then you may find it's helpful to adjust the field name for the case when two data sources have the fields with the same name, the detailed document regarding to this issue is here: http://chartit.shutupandship.com/docs/apireference.html#datapool

Image urls retrieved using facebook graph api break after certain amount of time

I have a rails(ruby 2.2.1, rails 4.2.0) application that uses the koala gem (2.0.0) to retrieve all the images from all the albums for the user. The code for the facebook service is as
class FacebookService
attr_reader :graph
def initialize(token)
#graph = Koala::Facebook::API.new(token)
end
def photos
your_photos, photos_of_you = [], []
albums_ids.map do |album_id|
#this query will combine fetch all the photos in any album + comments + likes associated with that image
your_photos += graph.get_connections(album_id, "photos", {limit: 100, fields: ["id", "source", "images", "height", "width", "created_time", "likes", "comments{id, message, from{name, picture}, created_time}"]})
end
photos_of_you = graph.get_connections("me", "photos", {limit: 100, fields: ["id", "source", "images", "height", "width", "created_time", "likes", "comments{id, message, from{name, picture}, created_time}"]})
(your_photos + photos_of_you).flatten
end
def albums_ids
albums.map { |album| album["id"] }
end
def albums
graph.get_connections("me", "albums")
end
end
and has been used as
fb = FacebookService.new current_user.oauth_token
photos = fb.photos
I am saving those urls in the db for further reference. I tried saving the source and the largest image from the images array but the urls keep going invalid. The problem is that when the above code is executed, the urls in the source and images aren't valid after certain amount of time(say 2-3 days). How can I retrieve image url that don't break later?
Thanks.
I filed a bug about this one a while back - it appears it's by design, and that there's some reason for those expiring URLs. The solution here is to actually cache image data, rather than just a URL.

Django ORM call to obtain multiple fk values?

models.py (derived from existing db)
class IceCreamComponent(models.Model):
name = models.CharField
#can be 'flavor', 'nut', etc
class IceCream(models.Model):
name = models.CharField
component = models.ForeignKey(IceCreamComponent)
value = models.CharField #will correspond to the component
The context behind this database is that 'IceCream' reports will come in from someone who's only purpose is to report back on a certain component (i.e. my 'extras' reporter will report the name of the ice cream and the extra it contained). It is assumed that all needed reports are in the db when queried so that something like:
IceCreams = IceCream.objects.values('name', 'component__name', 'value')
will return something akin to:
[
{'name': 'Rocky road', 'component__name': 'ice cream flavor', 'value':'chocolate'},
{'name': 'Rocky road', 'component__name': 'nut', 'value':'almond'},
{'name': 'Rocky road', 'component__name': 'extra', 'value':'marshmallow'},
{'name': 'Vanilla Bean', 'component__name': 'ice cream flavor', 'value':'vanilla'},
{'name': 'Vanilla Bean', 'component__name': 'extra', 'value':'ground vanilla bean'},
]
However, as you can imagine something like:
[
{'name': 'Rocky Road', 'ice cream flavor': 'chocolate', 'nut': 'almond', 'extra':'marshmallow' },
{'name': 'Vanilla Bean', 'ice cream flavor': 'vanilla', 'extra':'ground vanilla bean'}
]
is much more usable (especially considering I'd like to use this in a ListView).
Is there a better way to query the data or will I need to loop through the ValuesQuerySet to achieve the desired output?
Can't you reconstruct the list from the original result?
results = []
for row in vqueryset:
converted_row = {}
converted_row[row['component__name']] = row['value']
converted_row['name'] = row['name']
results.append(converted_row)
Of course you would want to paginate the original result before evaluating it (turning it into a list).
oh, you asked if there's a better way. I'm doing it this way because I couldn't find a better way anyway.
Here is the solution I came up with.
processing = None
output = []
base_dict = {}
for item in IceCreams:
# Detect change current site code from ordered list
if item['name'] != processing:
processing = item['name']
# If base_dict is not empty add it to our output (only first one)
# TODO see if there's a better way to do first one
if base_dict:
output.append(base_dict)
base_dict = {}
base_dict['name'] = item['name']
base_dict[item['component__name']] = item['value']

making separate array from existing json django

I have this array of JSON:
[{'pk': 4L, 'model': u'logic.member', 'fields': {'profile': 3L, 'name': u'1', 'title': u'Mr', 'dob': datetime.date(1983, 1, 1), 'lastname': u'jkjk', 'redressno': u'jdsfsfkj', 'gender': u'm'}}, {'pk': 5L, 'model': u'logic.member', 'fields': {'profile': 3L, 'name': u'2', 'title': u'Mr', 'dob': datetime.date(1983, 1, 1), 'lastname': u'jkjk', 'redressno': u'jdsfsfkj', 'gender': u'm'}}]
I want to make separate array of JSON for only fields property.
What I tried is:
memarr=[]
for index,a in data1:
print index
print a
memarr[index]=a[index].fields
And it is giving an error of:
too many values to unpack
Please correct.
First of all, data1 is a list, so you can't unpack it into 2 variables.
If you want the index, you have to use something like enumerate.
Second, you can't assign to a list via indexing if the key doesn't exist. You have to append or use another valid list insert method.
Third, a[index].fields doesn't really make sense - there is no key in a that would be associated with an integer index and fields is not an attribute.
You're probably looking for something like this:
memarr = []
for index, a in enumerate(data1):
memarr.append(a['fields'])
So many things wrong with that snippet...
Anyway:
memarr = [a['fields'] for a in data]

django-admin-tools 3 column layout not working

I'm using django-admin-tools 0.4.
Following the docs here so that I can get a 3 column layout.
I have managed to get the page to space correctly for 3 columns but the Modules can't move over to the 3rd column.
I can only drag from the left column to the middle but not right.
How can I get the modules to move between the 3 columns?
My dashboard.py can be viewed here.
I've attached a screenshot to show what result I have.
The main issue was that admin_tools_dashboard_preferences needs to be truncated(almost for every change being made to the dashboard.)
Also the first snippet of code on the documentation page didn't even work for me. I took snippets from other parts of the docs and they seemed to work no problems.
In the end my example dashboard looks something like this.
Remember to truncate your preferences.
class MyDashboard(Dashboard):
columns = 3
def __init__(self, **kwargs):
Dashboard.__init__(self, **kwargs)
# will only list the django.contrib.auth models
self.children += [
modules.ModelList('Authentication', ['django.contrib.auth.*',])
]
self.children.append(modules.Group(
title="My group",
display="tabs",
children=[
modules.AppList(
title='Administration',
models=('django.contrib.*',)
),
modules.AppList(
title='Applications',
exclude=('django.contrib.*',)
)
]
))
self.children.append(modules.LinkList(
layout='inline',
children=(
{
'title': 'Python website',
'url': 'http://www.python.org',
'external': True,
'description': 'Python programming language rocks !',
},
['Django website', 'http://www.djangoproject.com', True],
['Some internal link', '/some/internal/link/'],
)
))