Skip to content

Commit 7ca57a8

Browse files
committed
example copy plants to new account
1 parent 7e136ad commit 7ca57a8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

example_copy_plants_to_new_account.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This script will copy all plants from one FarmBot account to another.
2+
# Note: It will not copy any associated water, height, or spread curves ids
3+
# because they will not exist in the target account.
4+
5+
from main import Farmbot
6+
from time import sleep
7+
8+
source = Farmbot()
9+
target = Farmbot()
10+
11+
source.get_token("[email protected]", "password", "https://my.farm.bot")
12+
target.get_token("[email protected]", "password", "https://example.com")
13+
14+
source.set_verbosity(0)
15+
target.set_verbosity(0)
16+
17+
# Get all points from the API.
18+
# Note this will include plants, weeds, generic points, and tools.
19+
points = source.get_info("points")
20+
21+
# Filter out only the plants
22+
plants = [point for point in points if point["pointer_type"] == "Plant"]
23+
24+
# Copy each plant to the target account
25+
for plant in plants:
26+
27+
# Only copy the relevant fields
28+
plant_copy = {key: plant[key] for key in [
29+
"name",
30+
"pointer_type",
31+
"x",
32+
"y",
33+
"z",
34+
"openfarm_slug",
35+
"plant_stage",
36+
"planted_at",
37+
"radius",
38+
"depth"
39+
]}
40+
41+
# Print the progress
42+
plant_details = f"{plant["name"]} at ({plant["x"]}, {plant["y"]}, {plant["z"]})"
43+
progress = f"{plants.index(plant) + 1}/{len(plants)}"
44+
print(f"{progress} Copying {plant_details} to target account...")
45+
46+
# Add the plant to the target account
47+
target.add_info("points", plant_copy)
48+
sleep(0.5)

0 commit comments

Comments
 (0)