various methods to parse pages from thingiverse
[skdb.git] / clients / tb-get / tb-get.py
blobe814c4a18921c35d8198df74efb458ea8e926a33
1 #!/usr/bin/env python
2 # coding: utf-8
4 # Tangible Bit text mode client
5 # by Smári McCarthy <smari@fabfolk.com>
7 # TODO:
8 # Cache settings for some period between executions if running standalone
9 # See TODO lists in functions.
11 import sys
12 import os
13 import xmlrpclib
14 import ConfigParser
16 configfiles = ["tbdefaults.conf", "~/.tangiblebit/tb.conf"]
17 settings = ConfigParser.ConfigParser()
19 def LoadSettings():
20 # Load settings. RFC 822.
21 cfgs = []
22 for cfg in configfiles:
23 cfgs.append(os.path.abspath(os.path.expanduser(cfg)))
25 settings.read(cfgs)
27 def Connection():
28 # TODO:
29 # if username and password are set in settings, use the Authenticated XMLRPC module...
30 # if settings["ssl"] == True, use the SSL interface
31 return xmlrpclib.Server(settings.get("server", "xmlrpcpath"))
33 def Help(args):
34 print("tb-get - Tangible Bit text mode client")
35 print("------------------------------------------------------")
36 print("help - get help")
37 print("fetch - download object definition")
38 print("sites - get a list of sites")
39 print("materials - get a list of properties")
40 print("order - put in an order for an object")
41 print("login - log in to Tangible Bit server")
43 def Login(args):
44 if len(args) < 2:
45 print("Provide a username and password to log in.")
46 print("You can also specify these in the config file (%s) to log in automagically" % settings["configfile"])
47 return False
48 settings.set("server", "username", args[0])
49 settings.set("server", "password", args[1])
51 def LoggedIn():
52 # TODO: Perhaps this should check if they're actually valid?
53 return settings.has_option("server", "username") and settings.has_option("server", "password")
55 def Fetch(args):
56 # TODO: Fetching functionality...
57 # - GetObject not implemented on the XMLRPC
58 # - objects recieved need to be unpacked and put into a folder with appropriate files
59 conn = Connection()
60 objectname = args[0]
61 object = conn.GetObject(objectname)
63 def Sites(args):
64 # TODO: Search functions that make sense for looking up sites
65 # - Get a list of sites
66 # - Get details for a certain site
67 # - Get sites within a certain radius of a certain location
68 # - What orders are currently being processed at a site
69 # - What is the access model of a certain site
70 # - What sites are within a certain region
71 pass
73 def Materials(args):
74 # TODO: Search functions that make sense for looking up materials
75 # - which materials fulfil a certain set of properties
76 # - which objects use a certain material
77 # - which materials are available within a certain radius of a certain location
78 # - which materials are available within a certain region
79 # - which materials exist in a certain inventory
80 # - compare two or more materials
81 pass
83 def Order(args):
84 # TODO: Appropriate ordering functions
85 # - Place order (interactive?)
86 # - Set shipping destination
87 # - Change where to order from (only possible if order hasn't been processed)
88 # - Compare object prices between sites (if applicable)
89 if not LoggedIn():
90 print("E: You must log in to place orders.")
91 return False
93 pass
98 LoadSettings()
100 if __name__ == "__main__":
101 if len(sys.argv) < 2:
102 action = "help"
103 else:
104 action = sys.argv[1]
106 if action == "help": Help(sys.argv[2:])
107 elif action == "fetch": Fetch(sys.argv[2:])
108 elif action == "login": Login(sys.argv[2:])
109 elif action == "sites": Sites(sys.argv[2:])
110 elif action == "materials": Materials(sys.argv[2:])
111 elif action == "order": Order(sys.argv[2:])
112 else:
113 print("E: Unknown action. Try 'help'.")