Export data history

Posted almost 2 years ago by R gaynor

Post a topic
R
R gaynor

I think it would be really helpful if there was a way to export or download all of the data the app collects into a single spreadsheet. 


Honestly this is because I teach data science and I’d like to be able to graph weight changes, or run some analyses on how often my pets are using the litterbox (and for how long) to see if I can get a better idea of what is normal for them when they’re healthy and what it looks like when their stomachs are upset. Right now it looks like I would have to go one by one through every individual day and copy all of the information down by hand.

3 Votes


4 Comments

Sorted by
J

Joha Salinas posted 11 months ago

I'm also interested in being able to download the history of the data that my dives collects. I wonder if we could request it because I really need it to analyze my cats' weight VS the amount of food and frequency. 

2 Votes

A

Aaron Eichelberger posted 4 months ago

My cat started to lose weight a couple of weeks ago mysteriously and I was hoping to be able to print out the records for the Vet. I was quickly disappointed that I couldn't do that plus I could only see the information from the last couple of days.

1 Votes

K

Kenneth Meyerson posted 4 months ago

I wrote a python script leveraging this library to log in and download the last 30 days of datapoints because of the lack of support. I have gone so far as to automate a cron job to get the data periodically so I don’t miss anything.


While getting your data may seem intimidating, you need very little code to access your data.


This is a quick example python program I wrote to figure out how use the library to access my data:


from datetime import timedelta, date # Library for calculatinga 30 Day Offset 
from petkit_exporter.petkit import PetKit, PetEvent, CleanEvent # Library to log into petkit
import pandas as pd # Library to process data tables.

# Provide your login credentials
petkit_username = "…[email protected]"
petkit_password = "password"

# Attempt to login.
petkit = PetKit(petkit_username, petkit_password)
print("Login Success")

# Print devices attached to your account
devices = petkit.discover_devices()
print("Found Devices:")
print(devices)

# Requesting Data
records = []
Offset = 30 # 30 day limit.

Start = date.today()
End   = date.today() - timedelta(days=Offset)
print(f"Seeking Records from {Start.strftime("%Y%m%d")} to {End.strftime("%Y%m%d")}")

# Request the data per device (if you have litter bot like I do)
for device in devices:
    print(f"Seeking Records for device: {device}")
    for i in range(Offset):
        # Getting Daily Records
        retrieve_date = (Start - timedelta(days=i)).strftime("%Y%m%d")
        datapoints = petkit.get_device_records(device,retrieve_date)
        for datapoint in datapoints:
            records.append(datapoint)


# Print them to your console
for item in records:
    print (item)

# Separate the Data
pet_events_data = [event for event in records if isinstance(event, PetEvent)]
clean_events_data = [event for event in records if isinstance(event, CleanEvent)]

# Convert to Pandas Dataframes (fancy way to say format it for the excel file)
pet_events_df = pd.DataFrame(pet_events_data)
clean_events_df = pd.DataFrame(clean_events_data)

# Export Data to a CSV file (something you can import into Excel.
pet_events_df.to_csv("pet_events.csv", index=False)  # Set index=False to 
clean_events_df.to_csv("clean_events.csv", index=False)  # Set index=False to 


If you need some help running this code, I suggest either finding a friend who is tech savvy OR trying out ChatGPT to get this code running.

0 Votes

S

S Maker posted 3 months ago

I'd like that too, please.

0 Votes

Login or Sign up to post a comment