Getting the exact number of instagram followers - python-requests

I am trying to get the exact number of followers of a given instagram account but re is giving me an attribute error.
import requests
import re
user = "example"
url = 'https://www.instagram.com/' + user
r = requests.get(url).text
followers = re.search('"edge_followed_by":{"count":([0-9]+)}',r).group(1)
print(followers)
Error:
Exception has occurred: AttributeError
'NoneType' object has no attribute 'group'

The re.search documentation says
Return None if no position in the string matches the pattern
If the text does not include your pattern, it will return None, which certainly does not have a function group().
You should check if re.search returns a match before calling group on it.

Related

How to manually set the Firestore document ID saving a new document calling Firestore API?

I am finding the following problem trying to save a new document into Firestore database by calling the related POST API and manually setting the document ID.
I am using Python but I suppose that the problem is not related to the language.
I try to explain what I have done and what is not working. My first attempt (that works but automatically set the document ID on Firestore) was:
First of all, I created this JSON document that will be the payload of my API:
# Convert the record to a dictionary
doc = {
'fields': {
'surname': {'stringValue':record[2]},
'firstName': {'stringValue':record[1]},
'socialSecurityCode': {'stringValue':codici_fiscali_list_as_string},
'city': {'stringValue':record[4]},
'personalPhone': {'stringValue':record[5]},
'personalPhone2': {'stringValue':record[6]},
'personalEmail': {'stringValue':emails_list_as_string},
'pazPres': {'stringValue':record[7]},
'pazNotes': {'stringValue':record[8]},
'pazMemo': {'stringValue':record[9]},
'isArchived': {'booleanValue':isArchived},
'isMigrated': {'booleanValue':True},
#'decomposition_keyword_search_list':{'arrayValue':{'values':decomposition_keyword_search_list}}
"decomposition_keyword_search_list":{
"arrayValue":{
"values":[
]
}
}
}
}
then I perform the API call by these lines:
api_endpoint = 'https://firestore.googleapis.com/v1/projects/MY-PROJECT-NAME/databases/(default)/documents/test/'
response = requests.post(api_endpoint, json=doc)
It works fine and it put the expected document into my test collection. But in this way, the ID was automatically generated by Firestore. For some reason, I have to use the content of a variable as ID (my ID must be the value of my record[0] that is a unique string)
So I tried to change the previous API endpoint in the following way:
api_endpoint = 'https://firestore.googleapis.com/v1/projects/MY-PROJECT-NAME/databases/(default)/documents/test/'+ record[0]
I expected that it creates a document using the record[0] as a document ID but it seems that I am wrong since I am obtaining the following error message:
Error saving document: {
"error": {
"code": 400,
"message": "Document parent name \"projects/MY-PROJECT-NAME/databases/(default)/documents/test\" lacks \"/\" at index 71.",
"status": "INVALID_ARGUMENT"
}
}
So, what is wrong? What am I missing? How can correctly manually set the ID of the document that I am creating calling the previous API?
Take a look at the documentation for creating documents. If you want to specify a document ID, it says you should pass that as a query parameter called documentId:
The client-assigned document ID to use for this document.
Optional. If not specified, an ID will be assigned by the service.

How to get specific data from firebase with Flutter?

(EDİT)
I am getting error in below code, what I want to do is only get data of followed users, users are in a different collection, shared content is in a different collection, and
I'm getting an error on the 4th line, I hope I explained it correctly, I would appreciate if you could help.
Errors I get:
The getter 'data' isn't defined for the type
'Stream<QuerySnapshot<Map<String, dynamic>>>'.
Try importing the library that defines 'data', correcting the name to
the name of an existing getter, or defining a getter or field named
'data'.
My Code:
stream: FirebaseFirestore.instance.collection('posts').orderBy('datePublish',descending: true).snapshots().map((event) {
List following = [];
var userSnap = FirebaseFirestore.instance.collection("users").snapshots();
if(Provider.of<UserProvider>(context).getUser.following.contains(userSnap.data["uid"])){
following.add(event);
return following;
}
return following;
}),
userSnap.data, data is not defined!

Issue updating an order with an authorized user(FastAPI)

I don't know what I'm doing wrong here. I want to update an order with order id but I get TypeError: dict() takes exactly 1 positional argument (0 given). However, it worked fine when I updated a user.
#order_router.put('/update/{order_id}', response_model=Order_Pydantic)
async def update_by_order_id(order_id: str, order=OrderModel, Authorize: AuthJWT = Depends()):
try:
Authorize.jwt_required()
except Exception as e:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORISED, detail='Invalid Token'
)
await Order.filter(id=order_id).update(**order.dict(exclude_unset=True))
return Order_Pydantic.from_queryset_single(Order.get(id=order_id))
I've seen where the error is coming from. I was using order=OrderModel instead of order: OrderModel

how to write an Axios query where I don't know a parent value?

I have a simple firebase DB which looks like
someNode: {
pushId-A: {param1: 'some string'},
pushId-B: {param1: 'some other string')
}
Using Axios GET, is there a way to query someNode for the value of param1 where I don't know the value of the pushId?
I want it to return the pushId of the node that contains "param1: 'some string'.
[EDIT}
I understand now that this is not an Axios question, but rather a Firebase question.
I've read the firebase docs here:
Filtering Data
But when I send the get request with any paramaters other than the auth token, I get back a 400 code. Which tells me it is incorrectly syntaxed.
here is the last part of the DB url
a8/data/houses/-L4OiszP7IOzkfh1f1NY/houseName
where houseName = "Aubergine"
Trying to filter for houseName I am passing:
axios.get('/houses.json/' + '?orderBy="houseName"&startAt="A"' + '&auth=' + token)
I'm keeping the params separate so I can more easily read and change them. Concatenating the strings has no effect.
No matter what combination of params I pass I get the 400 error code. If I leave them off, then the data comes through as expected.
What am I doing wrong????

How to get the table name in AWS dynamodb trigger function?

I am new with AWS and working on creating a lambda function on Python. The function will get the dynamodb table stream and write to a file in s3. Here the name of the file should be the name of the table.
Can someone please tell me how to get the table name if the trigger that is invoking the lambda function?
Thanks for help.
Since you mentioned you are new to AWS, I am going to answer descriptively.
I am assuming that you have set 'Stream enabled' setting for your DynamoDB table to 'Yes', and have set up this as an event source to your lambda function.
This is how I got the table name from the stream that invoked my lambda function -
def lambda_handler(event, context):
print(json.dumps(event, indent=2)) # Shows what's in the event object
for record in event['Records']:
ddbARN = record['eventSourceARN']
ddbTable = ddbARN.split(':')[5].split('/')[1]
print("DynamoDB table name: " + ddbTable)
return 'Successfully processed records.'
Basically, the event object that contains all the information about a particular DynamoDB stream that was responsible for that particular lambda function invoke, contains a parameter eventSourceARN. This eventSourceARN is the ARN (Amazon Resource Number) that uniquely identifies your DynamoDB table from which the event occurred.
This is a sample value for eventSourceARN -
arn:aws:dynamodb:us-east-1:111111111111:table/test/stream/2020-10-10T08:18:22.385
Notice the bold text above - test; this is the table name you are looking for.
In the line ddbTable = ddbARN.split(':')[5].split('/')[1] above, I have tried to split the entire ARN by ':' first, and then by '/' in order to get the value test. Once you have this value, you can call S3 APIs to write to a file in S3 with the same name.
Hope this helps.
Please note that eventSourceArn is not always provided. From my testing today, I didn't see eventSourceArn presented in record. You can also refer to the links:
Issue: https://github.com/aws/aws-sdk-js/issues/2226
API: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_Record.html
One way to do it will be via pattern matching in Scala using regex:
val ddbArnRegex: Regex = """arn:aws:dynamodb:(.+):(.+):table/(.+)/stream/(.+)""".r
def parseTableName(ddbARN: String): Option[String] = {
if (null == ddbARN) None
ddbARN match {
case ddbArnRegex(_, _, table, _) => Some(table)
case _ => None
}
}

Resources