Understanding server requests: instances vs references - python-3.x

I am trying to understand a Python package called Instaloader and how many requests are actually being made to the Instagram server. With Instaloader, one can create a Profile instance from a given username with the following snippet of code:
loader = Instaloader()
loader.load_session_from_file(login_name)
profile = Profile.from_username(loader.context, target_profile)
Q1. Am I correct in assuming the last line makes a single request to the Instagram server? Am I also correct in assuming I am creating a data object (and not a reference) that is being stored in the "profile" variable?
profile_full_name = profile.full_name
Q2. Am I correct in assuming this does not make a request to the server, but retrieves a parameter from the data object in the profile variable?
followers = profile.get_followers()
Q3. Am I correct in assuming this makes another request to the server and stores the data object in the "followers" variable? The documentation says the return type is "NodeIterator[Profile]". Does this mean I am storing the data object for each profile from the target's followers? Or am I making a reference to each of those profiles?
Q4. If I am storing the data object for each profile, does that mean extracting information from the data object for these profiles will NOT make additional requests to the server? (Because I already have it stored in the "followers" variable?)
Or does it operate as a reference and thus: each moment I extract additional parameters from a follower profile, it will require an additional request to the server?

These answers were provided to me elsewhere:
A1. Yes, Profile.from_username() does make a single request to Instagram, which contains most of the profile metadata, and returns a Profile instance with that data included.
A2. Yes, full_name is already included in the data structure returned by Profile.from_username() and accessing it will in this case not trigger any further requests.
A3 & A4. get_followers() makes one request to the server and returns a NodeIterator. Some of the followers are already included with a thin data structure, containing only basic information. Iterating this iterator or accessing the items it yields will trigger further requests as required.

Related

Is there a way to filter in Django using the equal magic method?

Some background just in case there is a better way to do this other than the way I am trying:
I am requesting data of a rest API. When the data is received I want to check if a model containing this data already exists. The rest API does not give an ID for data entry so I cannot use this to see if a model instance already exists.
I have created an equal magic method for the model that checks several of the fields to see if they are equal and returning the appropriate boolean. This works fine when checking for example if instance == other_instance.
The issue arises when I try to filter or get to check the DB.
breach = Breach.objects.get(self=breach1)
I could check by specifying the fields each time but this would lead to some duplicated code over time and make the code base maintainable.
I am still newish to using Django so apologies if Django has a simple way of doing this.

How to access a connector / Data Base from the initial/instantiation Form/Page?

How to access a connector / Data Base from the initial/instantiation Form/Page?
Hi every body, any help will be appreciated.
I try to access using the API Rest, but the method need the activyty/task id or the instance flow id.
This is because the connector stores its result in a proces/local/Busines data model or Variables,
but in the initial form I don't have an
instance of the flow/task/activity and I can't access to the variable that stores the value.
I need to use the connector to access data base and to the Ldap
to get some values to show in the initial form before instantiating the process.
Is there any way to call a Groovy Script from initial Form?, if there is,
I can access from that script to the data base, and save this value into a form variable, to show it in the form I think.
P.S.: I use Bonita 7.2
thanks!
Sounds like you have a chicken and egg problem.
Can you instantiate the process with minimal data, then use a connector out to populate the BDM with the connector data, and then make the first step of your process the "initial" form? At that point you then have the case, taskid, etc.
If the data is not task/case specific, you can access the BDM data via the REST API and a custom query - i.e. you're not just limited to the API's that require the case/task/instance, etc. However, you may need to get clever with how you isolate that record. For example, I have some global parameters that I keep in in the BDM, and access them within my form by requesting the first record in that table via the rest API:
I created a variable called "globals" of type "External API" with the following REST call that retrieves the record with persistenceId=1:
../API/bdm/businessData/com.company.model.GlobalParameters/1
In your case, you probably need to use a REST Api extensions. Basically, you can create a new REST Endpoint using Groovy script. There is a documentation available here: http://documentation.bonitasoft.com/rest-api-extensions-808
Cheers

Adding manual relationship to your managed object

I have a managed object lets say products and I have another object that getting the data from another server and is already stored as managed object. There's nothing you in terms of the JSON data you get from the server that you can relate the two objects together. The only way is to do it manually before you get send the request. Is there a way to create a relationship that can do that using Restkit?
If you have the unique identifier of the source object in the request path or somewhere in the response body then you can use it in the mapping and perform a foreign key mapping to connect a relationship between the source and response objects.
If the identity is in the request path then you need to use RKRoute to prepare the request and #metadata.routing.parameters in your mapping to extract the identity. If it's in the response body then the standard mapping approach applies.
Once you have it, you map it into a temporary attribute on your destination object.
Once you have that you can perform your foreign key mapping.

save data in obtainPermanentIDsForObjects (NSIncrementalStore)

NSIncrementalStore has a required method "obtainPermanentIDsForObjects".
To get the ID's I have to create new row's in the database. Then to save the data in
executeRequest:withContext:error:, I have to hit the DB again.
Is there a reason why I shouldn't get new rowID's and save the data at the same time in obtainPermanentIDsForObjects?
The answer is probably not, if your entities have relationships.
To save a relationship, you need to uniquely identify the corresponding objects. Identifying an object requires your internal identifier which can be obtain via the permanent objectID (NSManagedObjectID).
But (some of) your objects won't have a permanent and internal ID yet because they haven't been handled yet in "obtainPermanentIDsForObjects"
In other words first you need to assign permanentID's (and thus also internalID's) before you can save references to them.

non-database field on ClearQuest form

Is there a way to use form fields that does not correspond to database field for temporary processings?
I.e. I want to add:
temp fields item1, item2
database field sum
button with record hook that sets sum = item1 + item2
As far as I know it's simply not possible with ClearQuest.
I've tried to do something similar and was told by our IBM consultant that the only way is to create a DB field for all variables.
You can't attach data to form fields really - those are representations of the underlying data, not something scripts interact with directly.
Adding temporary data to the underlying record (entity) itself sounds unlikely as well. Perhaps it's possible to abuse the perl API and dynamically attach data to entity objects but I personally wouldn't try it, you're liable to lose your data at the whim of CQ then ;-)
That does not however mean it's impossible to have temporary data.
The best way seems to me to be using the session object, which is explicitly intended for that purpose.
From the helpfile:
IBM Rational ClearQuest supports the
use of sessionwide variables for
storing information. After you create
sessionwide variables, you can access
them through the current Session
object using functions or subroutines,
including hooks, that have access to
the Session object. When the current
session ends, all of the variables
associated with that Session object
are deleted. The session ends when the
user logs out or the final reference
to the Session object ceases to exist.
There's some helpful documentation on this subject in file:///C:/Program%20Files/Rational/ClearQuest/doc/help/cq_api/c_session_vars.htm (Presuming a default installation on a windows machine, of course.)
Translating the code example in there into what you seem to be wanting, first you store the data you have calculated inside the session object:
$session->SetNameValue("item1", $value1);
$session->SetNameValue("item2", $value2);
Then in your calculation hook you retrieve the stored values and set the value of that totals field like this:
my $item1 = GetNameValue("item1");
my $item2 = GetNameValue("item2");
my $sum = $item1 + $item2;
$entity->SetFieldValue("some_totals_record", $sum);
Adjust to taste of course ;-)
ClearQuest schema designers often include 'temporary' fields in their record types. They do this so they perform operations on hooks to generate another value.
For example, for the Notes fields, there is a 'temporary' Notes_entry field that the user types the most recent note into, and when the record is saved, the value is added to the Notes_Log field. The next time the record is edited the Notes_entry field is cleared so the user can type a new Notes_entry.

Resources