mirror of https://git.envs.net/envs/botany.git
merge
This commit is contained in:
commit
f890724f16
|
@ -1,5 +1,5 @@
|
|||
# botany
|
||||
[![Screencap](https://asciinema.org/a/bbsqp00meurz3v5ltzc2jywif.png)](https://asciinema.org/a/bbsqp00meurz3v5ltzc2jywif)
|
||||
![Screencap](https://tilde.town/~curiouser/botany.png)
|
||||
|
||||
by Jake Funke - jifunks@gmail.com - tilde.town/~curiouser - http://jakefunke.online/
|
||||
|
||||
|
@ -13,7 +13,7 @@ Check in and water your plant every 24h to keep it growing. 5 days without water
|
|||
## getting started
|
||||
botany is designed for unix-based systems. Clone into a local directory using `$ git clone https://github.com/jifunks/botany.git`.
|
||||
|
||||
Run with `$ python botany.py`.
|
||||
Run with `$ python3 botany.py`.
|
||||
|
||||
*Note - botany.py must initially be run by the user who cloned/unzipped botany.py - this initalizes the shared data file permissions.*
|
||||
|
||||
|
@ -64,7 +64,7 @@ A once-weekly cron on clear_weekly_users.py should be set up to keep weekly visi
|
|||
|
||||
## requirements
|
||||
* Unix-based OS (Mac, Linux)
|
||||
* Python 2.x
|
||||
* Python 3.x
|
||||
* Recommended: 80x24 minimum terminal, fixed-width font
|
||||
|
||||
## credits
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env python2
|
||||
from botany import *
|
||||
|
||||
def ascii_render(filename):
|
||||
# Prints ASCII art from file at given coordinates
|
||||
this_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),"art")
|
||||
this_filename = os.path.join(this_dir,filename)
|
||||
this_file = open(this_filename,"r")
|
||||
this_string = this_file.read()
|
||||
this_file.close()
|
||||
print(this_string)
|
||||
|
||||
def draw_plant_ascii(this_plant):
|
||||
# this list should be somewhere where it could have been inherited, instead
|
||||
# of hardcoded in more than one place...
|
||||
plant_art_list = [
|
||||
'poppy',
|
||||
'cactus',
|
||||
'aloe',
|
||||
'flytrap',
|
||||
'jadeplant',
|
||||
'fern',
|
||||
'daffodil',
|
||||
'sunflower',
|
||||
'baobab',
|
||||
'lithops',
|
||||
'hemp',
|
||||
'pansy',
|
||||
'iris',
|
||||
'agave',
|
||||
'ficus',
|
||||
'moss',
|
||||
'sage',
|
||||
'snapdragon',
|
||||
'columbine',
|
||||
'brugmansia',
|
||||
'palm',
|
||||
'pachypodium',
|
||||
]
|
||||
if this_plant.dead == True:
|
||||
ascii_render('rip.txt')
|
||||
elif datetime.date.today().month == 10 and datetime.date.today().day == 31:
|
||||
ascii_render('jackolantern.txt')
|
||||
elif this_plant.stage == 0:
|
||||
ascii_render('seed.txt')
|
||||
elif this_plant.stage == 1:
|
||||
ascii_render('seedling.txt')
|
||||
elif this_plant.stage == 2:
|
||||
this_filename = plant_art_list[this_plant.species]+'1.txt'
|
||||
ascii_render(this_filename)
|
||||
elif this_plant.stage == 3 or this_plant.stage == 5:
|
||||
this_filename = plant_art_list[this_plant.species]+'2.txt'
|
||||
ascii_render(this_filename)
|
||||
elif this_plant.stage == 4:
|
||||
this_filename = plant_art_list[this_plant.species]+'3.txt'
|
||||
ascii_render(this_filename)
|
||||
|
||||
if __name__ == '__main__':
|
||||
my_data = DataManager()
|
||||
# if plant save file exists
|
||||
if my_data.check_plant():
|
||||
my_plant = my_data.load_plant()
|
||||
# otherwise create new plant
|
||||
else:
|
||||
my_plant = Plant(my_data.savefile_path)
|
||||
my_data.data_write_json(my_plant)
|
||||
draw_plant_ascii(my_plant)
|
11
botany.py
11
botany.py
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import division
|
||||
import time
|
||||
import pickle
|
||||
import json
|
||||
|
@ -249,7 +248,7 @@ class Plant(object):
|
|||
else:
|
||||
with open(visitor_filepath, mode='w') as f:
|
||||
json.dump([], f)
|
||||
os.chmod(visitor_filepath, 0666)
|
||||
os.chmod(visitor_filepath, 0o666)
|
||||
if not guest_timestamps:
|
||||
return self.watered_timestamp
|
||||
all_timestamps = [self.watered_timestamp] + guest_timestamps
|
||||
|
@ -473,7 +472,7 @@ class DataManager(object):
|
|||
sqlite_dir_path = os.path.join(self.game_dir,'sqlite')
|
||||
if not os.path.exists(sqlite_dir_path):
|
||||
os.makedirs(sqlite_dir_path)
|
||||
os.chmod(sqlite_dir_path, 0777)
|
||||
os.chmod(sqlite_dir_path, 0o777)
|
||||
conn = sqlite3.connect(self.garden_db_path)
|
||||
init_table_string = """CREATE TABLE IF NOT EXISTS garden (
|
||||
plant_id tinytext PRIMARY KEY,
|
||||
|
@ -490,9 +489,9 @@ class DataManager(object):
|
|||
|
||||
# init only, creates and sets permissions for garden db and json
|
||||
if os.stat(self.garden_db_path).st_uid == os.getuid():
|
||||
os.chmod(self.garden_db_path, 0666)
|
||||
os.chmod(self.garden_db_path, 0o666)
|
||||
open(self.garden_json_path, 'a').close()
|
||||
os.chmod(self.garden_json_path, 0666)
|
||||
os.chmod(self.garden_json_path, 0o666)
|
||||
|
||||
def migrate_database(self):
|
||||
conn = sqlite3.connect(self.garden_db_path)
|
||||
|
|
|
@ -6,6 +6,6 @@ garden_db_path = os.path.join(game_dir, 'sqlite/garden_db.sqlite')
|
|||
conn = sqlite3.connect(garden_db_path)
|
||||
c = conn.cursor()
|
||||
c.execute("DELETE FROM visitors")
|
||||
print "Cleared weekly users"
|
||||
print("Cleared weekly users")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
|
|
@ -581,6 +581,7 @@ class CursedMenu(object):
|
|||
"growing. 5 days without water = death. your\n"
|
||||
"plant depends on you & your friends to live!\n"
|
||||
"more info is available in the readme :)\n"
|
||||
"https://github.com/jifunks/botany/blob/master/README.md\n"
|
||||
" cheers,\n"
|
||||
" curio\n"
|
||||
)
|
||||
|
|
|
@ -40,10 +40,10 @@ def update_garden_db():
|
|||
# )
|
||||
# """.format(pid = "asdfasdf", pown = "jake", pdes = "big cool plant", page="25d", psco = str(25), pdead = str(False))
|
||||
|
||||
print c.execute(update_query)
|
||||
print(c.execute(update_query))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
#print "bigggg booom"
|
||||
#print("bigggg booom")
|
||||
|
||||
def retrieve_garden_from_db(garden_db_path):
|
||||
# Builds a dict of dicts from garden sqlite db
|
||||
|
@ -68,7 +68,7 @@ def retrieve_garden_from_db(garden_db_path):
|
|||
#init_database()
|
||||
#update_garden_db()
|
||||
results = retrieve_garden_from_db(garden_db_path)
|
||||
print results
|
||||
print(results)
|
||||
|
||||
|
||||
# con = sqlite3.connect(garden_db_path) #
|
||||
|
@ -77,7 +77,7 @@ print results
|
|||
# cur.execute("select * from garden ORDER BY score desc") #
|
||||
# blah = cur.fetchall() #
|
||||
# con.close()
|
||||
# print blah
|
||||
# print(blah)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue