-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBackup.py
40 lines (31 loc) · 1.56 KB
/
Backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Import following modules
import urllib.request
import pandas as pd # pip install pandas
from pushbullet import PushBullet # pip install pushbullet.py == 0.9.1
# Note: pip install openpyxl - Install this module
# Get Access Token from pushbullet.com
Access_token = "o.aUTXEomlNPUbJQpdzl4YxQjybOSE0uRz"
pb = PushBullet(Access_token) # Authentication
all_pushes = pb.get_pushes() # All pushes created by you
latest_one = all_pushes[0] # Get the latest push
url = latest_one['file_url'] # Fetch the latest file URL link
Text_file = "All_Chats.txt" # Create a new text file for storing all the chats
# Retrieve all the data store into Text file
urllib.request.urlretrieve(url, Text_file)
chat_list = [] # Create an empty chat list
# Open the Text file in read mode and read all the data
with open(Text_file, mode='r', encoding='utf8') as f:
data = f.readlines() # Read all the data line-by-line
# Excluded the first item of the list, coz first items contains some garbage data
final_data_set = data[1:]
# Run a loop and read all the data line-by-line
for line in final_data_set:
date = line.split(",")[0] # Extract the date
tim = line.split("-")[0].split(",")[1] # Extract the time
name = line.split(":")[1].split("-")[1] # Extract the name
messag = line.split(":")[2][:-1] # Extract the message
# Append all the data in a List
chat_list.append([date, tim, name, messag])
# Create a dataframe, for storing all the data in a excel file
df = pd.DataFrame(chat_list, columns=['Date', 'Time', 'Name', 'Message'])
df.to_excel("BackUp.xlsx", index=False)