Fake names detection [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a list of users. Each user has First name and Last name fields. Most of user details are accurate. From time to time, I can see users that signed up using fake details.
For example:
Valid: Alon Mask
In valid: Asd Dfds
I'm looking to find a way to check if name is legitim or not. What is the best approach to solve it?
My development stack is Python.

You can use the google cloude infotype API to extrat types of info from a given string
https://cloud.google.com/dlp/docs/quickstart-json
It works by sending a Json request to the API which will return the info you're looking for with minimum likelihood.
Example with phone number:
{
"item":{
"value":"My phone number is (206) 555-0123."
},
"inspectConfig":{
"infoTypes":[
{
"name":"PHONE_NUMBER"
},
{
"name":"US_TOLLFREE_PHONE_NUMBER"
}
],
"minLikelihood":"POSSIBLE",
"limits":{
"maxFindingsPerItem":0
},
"includeQuote":true
}
}
Response:
{
"result":{
"findings":[
{
"quote":"(206) 555-0123",
"infoType":{
"name":"PHONE_NUMBER"
},
"likelihood":"LIKELY",
"location":{
"byteRange":{
"start":"19",
"end":"33"
},
"codepointRange":{
"start":"19",
"end":"33"
}
},
"createTime":"2018-11-30T01:01:30.883Z"
}
]
}
}
https://cloud.google.com/dlp/docs/infotypes-reference#global has all the infotypes, you probably want experiment with those:
PERSON_NAME
A full person name, which can include first names, middle names or initials, and last names. Note: Not recommended for use during latency sensitive operations.
FIRST_NAME
A first name is defined as the first part of a PERSON_NAME. Note: Not recommended for use during latency sensitive operations.
LAST_NAME
A last name is defined as the last part of a PERSON_NAME.
Note: Not recommended for use during latency sensitive operations.

Related

Access sub category in JSON python [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
What is the code required to print the ContractName sub category (under result) ?
I know to get result I have my dictionary result :
response_dict = response.json()
print()response_dict["result"]
But how do I get ContractName??
{
"status":"1",
"message":"OK",
"result":[
{
"SourceCode":"test",
"ContractName":"DAO",
"CompilerVersion":"v0.3.1-2016-04-12-3ad5e82",
}
]
}
The value of result in your dictionary is a list. That list, in your example, contains one element which is another dictionary.
Therefore:
response_dict['result'][0]['ContractName']
...will give you what you need.

How do I elegantly control user question flow in Python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I am writing software in Python that needs to do the following:
Assign values to variables by getting input from the user
Choose the next question to ask the user based on their previous answer
Take action based on the variables once all questions have been asked
I saw an example on here which set questions in a Python dictionary, and that included what question to jump to based on the answer entered. This was very neat and easy to follow, so I started implementing that. I was then going to follow this by comparing the variables to a second dictionary which would then determine what action to take - a decision matrix I believe this is called.
I came to a grinding halt, however, on a question that asks for the date. I have no idea how to check the date is in the right format, and how to get Python to check a valid date has been entered and, if it has, to move to a specific next question. Turns out there is more than one occurrence of this problem.
The code follows below. You can easily see in questions relating to candate and frequency1 and frequency2 where I have come a cropper.
The question, I guess, is whether I can do this using a dictionary to define questions and flow, or whether I will have to suck it up and create a load of IF statements. The only reason I started with dictionaries is to make it easy to implement, maintain and expand. Once I have nailed this, I need to implement much bigger question sets, so would like the question flow to be as elegant and simple as possible.
Apologies for obfuscating the questions.
If you answer, I would just point out this is the first thing I have tried to write in Python beyond asking for someone's name and printing it so simpler is better for me! Thanks!
#Stopquestions is a dictionary containing all the questions that could be asked of the user. It also controls the flow of the questions.
stopquestions = {
'stopconfirm':
{
'prompt':'Do you want to take this action? Y/N ',
'Y':'prev',
'N':'genericerror'
},
'prev':
{
'prompt':'Previously done? Y/N ',
'Y':'bamerch',
'N':'frequency1'
},
'bamerch':
{
'prompt':'Was that with B or M? B/M ',
'B':'candate',
'M':'candate'
},
'candate':
{
'prompt':'What was the date? DD/MM/YYYY ',
'DD/MM/YYYY':'length',
'Anything but the above':'genericerror'
},
'length':
{
'prompt':'Yes or no with reference to length? Y/N ',
'Y':'frequency2',
'N':'frequency2'
},
'frequency1':
{
'prompt':'Choose freq? W/F/M/Q/A ',
'W/F/M/Q/A':'dis',
'Anything but the above':'genericerror'
},
'frequency2':
{
'prompt':'Choose freq? W/F/M/Q/A ',
'W/F/M/Q/A':'end',
'Anything but the above':'genericerror'
},
'dis':
{
'prompt':'Disagreement with recent? Y/N ',
'Y':'end',
'N':'end'
},
'genericerror':
{
'text':'This is a basic example of how we can catch errors.',
'action':'end'
}
}
I would look at the date, and if it does not match the formatting ask the user to reinput the data.
arrow is a great tool to handle this:
import arrow
try:
arrow.get('01/01/2021', 'MM/DD/YYYY')
except arrow.parser.ParserMatchError:
print(False)
https://arrow.readthedocs.io/en/latest/
UPDATE
def check_format(date, fmt='MM/DD/YYYY'):
try:
x = arrow.get(date)
return x.format('MM/DD/YYYY')
except (arrow.parser.ParserMatchError, arrow.parser.ParserError):
if fmt: # 'MM/DD/YYYY'
try:
x = arrow.get(date, fmt)
return x.format('MM/DD/YYYY')
except arrow.parser.ParserMatchError:
return False
return False
print(check_format('2021-01-01')) # 01/01/2021
print(check_format('2021-01-01', 'MM/DD/YYYY')) # 01/01/2021
print(check_format('01/01/2021', 'MM/DD/YYYY')) # 01/01/2021
print(check_format('June was born in May 10 1980', 'MMMM D YYYY'))) # 05/10/1980
print(check_format('01/2021', 'MM/DD/YYYY')) # False

I want to print names of employees who have both work number and mobile number.below is my json body [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to print firstname of employees who have both work number and mobile number. Below is my json body. I am facing difficulty in getting inside phoneNumbers attribute. My final output should be: "Adhi as Adhi has both work and mobile numbers".
I am not able to iterate the inner dictionary of phoneNumbers attribute.Can you please help me on this.
This is my python code
for i in Data['users']:
for j in i['phoneNumbers']:
for i in range(len(j)):
if j['type']=="work" and j['type']=="mobile":
print("Firstname",i['firstName'])
You can loop over the users and check if the work and mobile number are present:
for user in Data['users']:
has_mobile_number = False
has_work_number = False
for phonenumber in user['phoneNumbers']:
if phonenumber['type'] == 'work':
has_work_number = True
if phonenumber['type'] == 'mobile':
has_mobile_number = True
if has_work_number and has_mobile_number:
print('Firstname', user['firstName'])
Also, I recommend not using i and j when not talking about indexes. In you code, i is a dict representing a user and j is a dict representing a phone. I replaced them with user and phonenumber for more clarity in the code above.

Python youtube api status.rejectionReason [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I've looked through the documentation here: https://developers.google.com/youtube/v3/docs/videos
But am unsure how to access status.rejectionReason with python. I've been using youtube-uploader for my uploading, and I dont believe there is any commands to return the reason a video was rejected. The ideal scenario would be to get a list of all my videos, check which ones have been rejected, then return the links of the ones that have been rejected.
From what I can see the rejectionReason is within a JSON "videos resource" format. You can access this with Python's built-in JSON library:
from json import load
with open('video.json') as file: # Opens the JSON file and assigns it to the variable 'file' within the loop
data = load(f) # Loads the file into a dictionary which you can access with key:value pairs
The JSON file provided as a sample on the site follows this format for the rejectionReason:
"status": {
"uploadStatus": string,
"failureReason": string,
"rejectionReason": string,
"privacyStatus": string,
"publishAt": datetime,
"license": string,
"embeddable": boolean,
"publicStatsViewable": boolean
}
So your final script would look like this I believe:
from json import *
def get_rejection_reason(file):
with open(file) as f:
data = load(f)
return data["status"]["rejectionReason"]
get_rejection_reason("video.json")

Python dict, extracting values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am having trouble to query my database maybe someone could give me a hand.
I am using a django application so I guess Sqlite3 >> and the output I would like to get is the score value
b = Answer.objects.get(id = 23)
which give me an output of :
<Answer: Answer to questionID '4' : AnswerID '23'>
when I do :
b.values
I get a dict in the form :
['{
"1)Long descriptive text":Score,
"2)Long descriptive text":Score,
"3)Long descriptive text":Score,
"4)Long descriptive text":Score
}']
with score beeing an Integer from 0 to 100 so for example "Long descriptive text":85
I need to extract the score using a query but I can't manage to do it
Normaly for a Dict[key:value] I would do a Dict[key] but here I do not know how to do it
could you give me a hand
Thx you very much
This looks suspiciously like Django If so:
so b = Answer.objects.get(id = 23) is not truely that - what you are seeing is the str function of the Answer when you print it off. because you used .get rather then a .filter you get the object rather then a QuerySet (which you can think of as being a list).
Basically, I suspect you shouldn't be using values, but accessing the data... something like
b = Answer.objects.get(id=..)
b.score
or if you wanted to loop over other answers:
answers = Answer.objects.filter(...)
for a in answers:
a.score
for what the .score is, look in your models.py file - look what parameters is has (things looking like score = models.IntegerField() etc, then you would use a.score)

Categories