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 was wondering if there was a way to convert someones username to their ID requested upon a different user. Basically when a user requests for someone elses ID, they type in their name and it returns the specified users ID.
I'm totally new to python and stackoverflow, so any help is very helpful Thank You.
EDIT: Since I am creating individual user files for each user I use a users ID to name them, now I just need something that will convert someones username into their ID.
for this you can save the username in dict in python so basically you would create a dictionary with a username as key i.e.
desc={"Ali":123,"Mathew" :1234}
so print desc["Mathew"]; would print 1234 which is id of Mathew
Related
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 months ago.
Improve this question
I am working on a project of making restaurant ordering system using basic concepts of python. I need to put a logic to store every ordered item of customer and show his order history.
I am beginner at programming so, i not able to think of a logic yet. Please help
How about a Person class that has a variable of type list named orders.
Now you can append the orders list with an item if a person orders something.
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 10 months ago.
Improve this question
I'm currently working on a ROBLOX Integrated discord bot with discord.py and have stumbled into an issue with checking if the user is in a group. I have already got a table of all groups and ranks, but have no clue how to iterate through it. The JSON structure is similar to as follows:
{
data:[{"group":{id:1,"name":"RobloHunks","memberCount":36351},"role":{"id":169,"name":"--","rank":1}},{"group":{id:2,"name":"LOL","memberCount":157765},"role":{"id":209,"name":"Cheezburgers","rank":1}}]
}
In a real example, there would be more than just two groups but I was wondering if there was any way to iterate through and check if the group ID is equal to 1 and then get the role associated with the group? I couldn't find a solution anywhere else.
So basically, data is a key and the bracket block is a value. That value is a list of dictionaries and the group key corresponds to another dictionary this one containing the id.
So if the json is stored in a variable called x then doing
x[‘data’][0][‘group’][‘id’]
will get one of them. A loop would be something like
for i in range(len(x[‘data’])):
user_id = x[‘data’][i-1][‘group’][‘id’]
if user_id == ‘1’:
print(x[‘data’][i-1][‘role’])
Hopefully this helps. The json would need to be correct though!
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 to implement a program which analyzes friendship. There will be a text file which will contain group of friends.so when user input a name from the group, the program shows who are this person's friends.
For example, the text file contains,
Erina;Mira; Kyla;
If user inputs Mira it will show other person as her friends..
I need to store the text file data in a data structure.. So what kind of data structure will be suitable for this in python? Should I go for a dictionary??
( The question asks for nested data structure)
Yes a dictionary would be your best bet. You could store the name of the person as the key and the a list of friends as the value. You can then append friends to the list like this:
friends_dict = dict()
friends_dict['john'] = []
friends_dict['john'].append("lisa")
print(friends_dict)
$ {'john':['lisa']}
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 4 years ago.
Improve this question
Please explain how to get user.id and user.name of client who talking with my bot in balebot. There is a peer class, but i don't know how exactly it works?
its a simple way to use get_effective_user() function to get peer_id or accesshash, see:
user_peer=update.get_effective_user()
user_id = user_peer.peer_id
But if you need more you can get name and other feilds of user from an Update Json. like this :
def text_received(bot, update):
for user in update.users:
print(user.get_json_object())
....
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 5 years ago.
Improve this question
I am new to flask and python. I have a website to which users can log in. I need to improve the security.
what i want to do is: when a user try many wrong passwords, I ban him further trying, ask him email and ask the user to reset password in the case the user forget the password.
I reviewed documentations about flask-admin, flask-secure. Since I am new to this, don't know where to start.
does flask-secure provide features to do what I want? or should I look into something also?
I'm not sure if I approve of this feature. But it could be achieved by either a field in the user table of your database or a runtime dictionary. Choose whichever gives you the level of persistence you want.
When a user attempts to log in and fails you simply increment this field. And if the field reaches a certain value you lock the user or do whatever you want.
Sending an email in python can be found at the docs.
As for a password reset system.
When a user needs to reset their password you generate a key. This can be a base64-encoded string of random bytes. This key can be stored in the user table with en expiry datetime.
Now you can create a route in flask that takes this key as path- or query-parameter.
So when a user needs to reset their password you can send them a unique link with this key as a path- or query-param (whichever you choose).