A-Git-Chatroom [Part-2]
- OnoSureiya
- Apr 7, 2020
- 2 min read
Let us begin by understanding the basic functions of a chatroom. A "Chatroom" is an area on the Internet or other computer network where users can communicate, typically one dedicated to a particular topic. Now in our case, we will be looking at a different version of a chatroom where we can explore the common git commands.
Let's begin by defining what we want our chatroom to provide. Our chatroom must allow different users to type at the same time, however, updates will only occur on user input and not automatically as seen in common approach. We can do that using asynchronous programming concept. However, in this article, we will not be taking a look at that.
Objectives:
1) Have Usernames based on their Git Profiles
2) Have multiple people's message by differentiate based on their usernames.
3) Allow other users to view your messages.
Main Code: https://github.com/AmanPriyanshu/chatroom
setup.py
Now let us understand when we initiate git. We must config our email and name using the commands:
"git config --global user.name "+name,
"git config --global user.email "+email
Now here "name" and "email" variables will have the user input of their name and GitHub email. Followed by this we will have to set up this repository to its room_name branch. This will allow particular channels of chat and groups can be formed. This can be done using the following command:
`git branch `+room_name
`git checkout `+room_name
The above commands focus on updating the particular branch of the repository. And for our understanding, this could be interpreted or rather used as rooms.
Followed by this we use the command:
`git config credential.helper store`
To store the username and password so the user does not have to re-enter their username and password every time they push to the repository.
chatroom.py
After executing setup.py let us create the main backbone of the chat mechanism. So here we have already saved the username of the user and we extract it from:
`git config --list`,
this gives us our config attributes and one such attribute which we set before was
`user.name=OnoSureiya`
We can extract this attribute using the find() function in python. Once we find this username it is simply used as the username of the particular user.
Now for updating posts we will follow the following sequence of steps:
Firstly, we will update and write to text file called "chats.txt". Here we will write to the text file using the commands:
`
file_w=open("chats.txt","a")
file_w.write(txt+"\n")
file_w.close()
`
After that, we will update the GitHub branch of the repository where when pulled by the other users will allow them to view your messages. The following commands will be used to update the chat logs on the chats.txt.
`
'git pull'
'git add -A'
'git commit -m "Update"'
'git pull origin '+room_name
'git push origin '+room_name
clear
`
This will be iteratively called (only broken using: '-e'). Now as you can see this a simple use-case of the subprocess library of python to integrate it with git. I hope you enjoyed this simple project as a method to explain the different methods of git.
Comments