class StockTa(object): HOST = "www.stockta.com" PORT = 80 ANALYSIS_PATH = "/cgi-bin/analysis.pl?symb=%s" THRESHOLD = 5 def __init__(self): self.site = Site(self.HOST, self.PORT) self.cache = {} def get_price_levels(self, symbol): prices = self.cache.get(symbol) if prices: return prices path = self.ANALYSIS_PATH % (symbol) raw = self.site.fetch(path) soup = BeautifulSoup(raw) try: summary = soup.body.find("td", text="Last Trade").parent.parent.parent.findAll("tr")[1].findAll("td") prices = {} prices['open'] = float(summary[4].string) prices['close'] = float(summary[1].font.string) prices['low'] = float(summary[6].string) prices['high'] = float(summary[5].string) prices['resist'] = self.find_resist(soup) prices['support'] = self.find_support(soup) self.cache[symbol] = prices return prices except Exception, e: print "Failed to get price levels for %s: %s" % (symbol, e) return {}
def get_directory_locations(self): c = self.context site = Site.Get(self.context) acre_dir = "~/acre" site_dir = "~/%s" % site.conf("id") name = raw_input( "Enter the directory where you want to install acre (default: %s):" % acre_dir) if not name: name = acre_dir c.options.acre_dir = os.path.expanduser(name.strip()) name = raw_input( "Enter the directory where you want to install %s (default: %s):" % (site.conf("id"), site_dir)) if not name: name = site_dir c.options.site_dir = os.path.expanduser(name.strip()) site.set_site_dir(c.options.site_dir)
def __call__(self): site = Site.Get(self.context) lib = None lib_app = App.Get(self.context, "lib") last_tag = lib_app.last_tag() if last_tag: lib = "//%s.%s.www.tags.svn.freebase-site.googlecode.dev" % ( last_tag, "lib") else: lib = "//lib.www.trunk.svn.freebase-site.googlecode.dev" print ''' // WARNING: This is an auto-generated file by //trunk/scripts/sitedeploy.py. // If you make changes to this file, please adjust ActionCreateRoutes.__call__ in there too. var codebase = "%s"; var tags_codebase = "%s"; var environment_rules = { "labels" : { "lib": "%s", "default" : "//default.dev", ''' % (site.conf("acre_id_suffix_trunk"), site.conf("acre_id_suffix_tags"), lib) apps = site.apps() for i, app_key in enumerate(apps): if app_key == "lib": continue app = App.Get(self.context, app_key) last_tag = app.last_tag() if last_tag: print ' "%s": "//%s.%s" + tags_codebase%s' % ( app_key, last_tag, app_key, i < len(apps) - 1 and "," or "") else: print ' "%s": "//%s" + codebase%s' % ( app_key, app_key, i < len(apps) - 1 and "," or "") print ''' }, "prefix" : [] }; acre.require(environment_rules.labels.lib + "/routing/router.sjs").route(environment_rules, this); ''' return True
def __call__(self): c = self.context config, app_id, app_version = Site.ResolveConfig( c, c.options.config, site_dir=c.options.site_dir, host=c.options.host) print config return True
def __call__(self): c = self.context c.set_action("create_tag") if not (c.options.app and c.options.version): return c.error( 'You have to specify a valid app and version to create a tag out of.' ) site = Site.Get(c) if not site: return c.error( "Could not figure out location of site. You can specify --site_dir as an option, or run the script from within a site svn checkout directory structure to figure it out automatically." ) acre = Acre.Get(c) if not acre: return c.error( "Could not get an acre instance. You can specifiy --acre_dir, or --acre_version with a valid acre branch or trunk" ) from_branch_app = App.Get(c, c.options.app, c.options.version) tag_app = from_branch_app.create_tag() #if not no_static: r = ActionStatic(c)(app=tag_app) if not r: tag_app.remove_from_svn() return c.error( 'Failed to create static files for "%s" - tag removed from SVN.' % tag_app) c.log('Created "%s"' % tag_app, color=c.BLUE) return True
def appengine_logs_url(self): c = self.context if not c.options.host: return "" site_config, appengine_app_id, appengine_app_version = None, None, None try: site_config, appengine_app_id, appengine_app_version = Site.ResolveConfig( c, c.options.config, c.options.site_dir, c.options.host) except: #We really don't care if we found a config, speedtests can be run on arbitrary hosts. pass if not appengine_app_id: return None self._ae_logs_params["app_id"] = appengine_app_id self._ae_logs_params[ "filter"] = self._ae_logs_params["filter"] % self.runid return "%s?%s" % (self._ae_dashboard, urllib.urlencode(self._ae_logs_params))
def __call__(self, app=None): c = self.context site = Site.Get(c) acre = Acre.Get(c) if not acre: return c.error("Can't continue without an acre instance.") if not (acre.is_running() or (acre.build(target='devel', config_dir="%s/appengine-config" % site.site_dir) and acre.start())): return c.error( "There was an error starting acre - cannot generate static files without a running acre instance." ) c.set_acre(acre) success = c.googlecode_login() if not success: return c.error( 'You must provide valid google code credentials to complete this operation.' ) if not app: app = c.current_app if not app.tag: return c.error('You can only create static files for app tags') r = app.statify() return r
def __init__(self): self.site = Site(self.HOST, self.PORT) self.cache = {}
class StockChartSignals(object): HOST = "stockcharts.com" PORT = 80 MIN_PRICE = 10.0 MIN_VOLUME = 1000000.0 # summary of the signals SIGNAL_SUMMARY_PAGE = "/def/servlet/SC.scan?s=runreport,predefall" # interested exchanges EXCHANGES = ["NASD", "NYSE", "AMEX"] # each identifies the description of a specific signal BULL_CANDLES = [ " Bullish Engulfing", " Piercing Line", " Morning Star", " Rising Three Methods", " Dragonfly Doji", " Hammer", "Breakaway Gap Ups", "Runaway Gap Ups", ] BEAR_CANDLES = [ " Bearish Engulfing", " Evening Star", " Falling Three Methods", " Gravestone Doji", " Shooting Star", "Breakaway Gap Downs", "Runaway Gap Downs", ] # below are some other signals available from the site BULL_SIGNALS = [ "New 52-week Highs", "Strong Volume Gainers", "Bullish 50/200-day MA Crossovers", "Bullish MACD Crossovers", "Improving Chaikin Money Flow", "New CCI Buy Signals", "Parabolic SAR Buy Signals", "Stocks in a New Uptrend (Aroon)", "Stocks in a New Uptrend (ADX)", "Gap Ups", "Runaway Gap Ups", " Piercing Line", " Bullish Harami", " Dragonfly Doji", " Hammer", "P&F Bullish Signal Reversal Alerts", "P&F Bullish Catapult Alerts", "P&F Bullish Triangle Alerts", "Oversold with an Improving RSI", "Moved Below Lower Bollinger Band", "Breakaway Gap Ups", "Island Bottoms", " Bullish Engulfing", " Morning Star", " Three White Soldiers", ] BEAR_SIGNALS = [ "Overbought with a Declining RSI", "Moved Above Upper Bollinger Band", "Runaway Gap Downs", " Dark Cloud Cover", " Bearish Harami", " Filled Black Candles", "New 52-week Lows", "Strong Volume Decliners", "Bearish 50/200-day MA Crossovers", "Bearish MACD Crossovers", "Declining Chaikin Money Flow", "New CCI Sell Signals", "Parabolic SAR Sell Signals", "Stocks in a New Downtrend (Aroon)", "Stocks in a New Downtrend (ADX)", "Island Tops", "Breakaway Gap Downs", " Bearish Engulfing", " Evening Star", " Three Black Crows", " Gravestone Doji", " Shooting Star", "P&F Bearish Signal Reversal Alerts", "P&F Bearish Catapult Alerts", "P&F Bearish Triangle Alerts", ] def __init__(self): self.site = Site(self.HOST, self.PORT) self.signal_paths = {} self.bulls = {} self.bears = {} def scan(self): self.load_signal_paths() self.load_signals(self.BULL_SIGNALS, self.bulls) self.load_signals(self.BEAR_SIGNALS, self.bears) def load_signal_paths(self): print "Start to load signal paths..." raw = self.site.fetch(self.SIGNAL_SUMMARY_PAGE) soup = BeautifulSoup(raw) signal = "N/A" try: rows = soup.findAll("tr", {"class":"odd"}) + soup.findAll("tr", {"class":"even"}) for row in rows: fields = row.findAll("td") signal = fields[0].string if signal is not None: signal_path = fields[6].a['href'] symbol_count = int(fields[6].a.string) if symbol_count > 0: self.signal_paths[signal] = signal_path else: print "Skip signal %s as its count is ZERO" % (signal) except Exception, e: print "Failed processing signal paths %s: %s" % (signal, e) print "Loaded signal paths"
def __init__(self): self.site = Site(self.HOST, self.PORT) self.signal_paths = {} self.bulls = {} self.bears = {}
def __call__(self): c = self.context if not c.options.site_dir: raise FatalException( "You must specify a directory to install the site in with --site_dir." ) site = Site.Get(c) acre = Acre.Get(c) if not acre: return c.error( "Could not get an acre instance. You can specifiy --acre_dir, or --acre_version with a valid acre branch or trunk" ) success = c.googlecode_login() if not success: return c.error( 'You must provide valid google code credentials to complete this operation.' ) self.site_checkout = c.options.acre_dir + '/webapp/WEB-INF/scripts/%s/%s' % ( site.conf("repository"), site.conf("id")) try: os.makedirs(self.site_checkout) self.site_checkout += '/svn' except: return c.error( 'The directory %s already exists, or unable to create directory.' % self.site_checkout) r = site.checkout(self.site_checkout) if not r: return False r = c.symlink(self.site_checkout, site.site_dir) config_dir = "%s/appengine-config" % site.site_dir r = Acre.Get(c).build(target="devel", config_dir=config_dir) if not r: return c.error('Failed to build acre under %s' % c.options.acre_dir) c.log("*" * 65) c.log("") c.log("In order to run the site:") c.log( "\t1. Run the acre server: \n cd %s; ./acre -c devel -d %s appengine-run" % (c.options.acre_dir, config_dir)) c.log("\t2. Visit http://devel.sandbox-freebase.com:%s" % c.options.acre_port) c.log("%s is now installed in %s" % (site.conf("id"), site.site_dir)) c.log("") c.log("*" * 65) return True
def __call__(self): c = self.context site = Site.Get(c) acre = Acre.Get(c) config, app_id, app_version = Site.ResolveConfig( c, c.options.config, c.options.site_dir, c.options.host) if not site: return c.error( "Could not figure out location of site. You can specify --site_dir as an option, or run the script from within a site svn checkout directory structure to figure it out automatically." ) if not acre: return c.error( "Could not get an acre instance. You can specifiy --acre_dir, or --acre_version with a valid acre branch or trunk" ) if not config: return c.error( "You have to specify an acre build target with -c e.g. -c sandbox-freebasesite or a host with --host e.g. --host dev.sandbox-freebase.com" ) (r, result) = acre.build(config, config_dir="%s/appengine-config" % site.site_dir, war=True) if not r: return c.error("Acre failed to build, aborting.") if not c.options.nosite: status = acre.start(war=True) if not status: return c.error( 'Could not start new acre war bundle under appengine development server, aborting deployment' ) c.log("\nDeployment Summary " + "*" * 45 + "\n", color=c.BLUE) c.log(" Config: %s" % config, color=c.BLUE) c.log(" Deployed URL: http://%s" % acre.site_host(True), color=c.BLUE) if app_version is None: c.log(" AppEngine URL: http://%s.appspot.com/" % app_id, color=c.BLUE) else: c.log(" AppEngine URL: http://%s.%s.appspot.com/" % (app_version, app_id), color=c.BLUE) c.log( " AppEngine Dashboard: https://appengine.google.com/dashboard?&app_id=%s\n" % app_id, color=c.BLUE) c.log("*" * 65 + "\n", color=c.BLUE) for directory in acre.site_dir(war=True): if os.path.isdir(directory + '/googlecode'): shutil.rmtree(directory + '/googlecode') if not c.options.nosite: apps = acre.fs_routed_apps() if not len(apps): raise FatalException( "Something went wrong, there are no apps to bundle with Acre, aborting!" ) for app in apps: result = app.copy_to_acre_dir(war=True) if not result: c.error( 'Failed to copy %s to app-engine bundle, continuing with other apps...' % app) # By default, push the environments app too unless --failover was specified. if not c.options.failover: acre.bundle_environments() c.log('The following apps were bundled:\n') for app in sorted(apps): c.log('\t%s' % app) acre.bundle_static_files() c.log('\nStarting deployment...', color=c.BLUE) if not acre.deploy(target=config): return c.error('Deployment failed.') if c.options.failover: c.log('\nStarting deployment of failover version...', color=c.BLUE) r = acre.prepare_failover() if not r: return c.error( 'Failed to prepare failover version of acre, aborting.') acre.bundle_environments() if not acre.deploy(config): return c.error('Failover deployment failed.') return True
def main(): # OPTION PARSING valid_actions = [ ("setup_acre", "create a local acre instance", ActionSetupAcre), ("setup_site", "create a local site instance", ActionSetupSite), ("setup", "\tsetup acre and freebase-site and link them", ActionSetup), ("deploy_acre", "deploy an acre instance to production app-engine", ActionDeployAcre), ("setup_dns", "setup freebase site dns for your host", ActionSetupSimpleDNS), ("setup_wildcard_dns", "setup wildcard dns for your host - Mac OS X only", ActionSetupWildcardDNS), ("info", "provide information on all apps or a specific app", ActionInfo), ("create_branch", "creates a branch of your app", ActionCreateAppBranch), ("create_tag", "creates a tag of your app", ActionCreateAppTag), ("create_static", "creates a static bundle and writes it to the provided tag", ActionStatic), ("speedtest", "run a speedtest", ActionSpeedTest), ("getids", "get freebase mids for a given type - useful for speedtests", ActionGetIds), ("listapps", "get a list of apps for this site", ActionListApps), ("create_routes", "create the routes configuration that will point to the last tag of every app", ActionCreateRoutes), ("test", "\ttest", ActionTest) ] usage = """%prog action [options] \nActions: """ usage += "\n".join(["\t%s\t%s" % a[:2] for a in valid_actions]) parser = OptionParser(usage=usage) parser.add_option("-u", "--user", dest="user", help="google code username - e.g. [email protected]") parser.add_option("-p", "--password", dest="password", help="google code password") parser.add_option("-b", "--verbose", dest="verbose", action="store_true", default=False, help="verbose mode will print out more debugging output") parser.add_option("", "--acre_dir", dest="acre_dir", default=None, help="the local acre directory") parser.add_option( "", "--acre_version", dest="acre_version", default=None, help= "an svn version of acre - either 'trunk' or a branch number like '34'") parser.add_option( "", "--acre_host", dest="acre_host", default="z", help="the hostname that you will use to address this acre installation" ) parser.add_option("", "--site_dir", dest="site_dir", default=None, help="the local site directory") parser.add_option("", "--acre_port", dest="acre_port", default=8115, help="the port you want to serve acre from") parser.add_option( "-c", "--config", dest="config", help="acre configuration target - e.g. sandbox-freebasesite or devel") parser.add_option( "-v", "--version", dest="version", default=None, help= "a version of the app - e.g. 12 - use 'latest' to auto-detect the last version branched" ) parser.add_option("-t", "--tag", dest="tag", default=None, help="a tag of the app - e.g. 12b") parser.add_option( "-a", "--app", dest="app", default=None, help= "an app id - e.g. /user/namesbc/mysuperapp or an app key under /freebase/site - e.g. homepage" ) parser.add_option( "-d", "--dependency", dest="dependency", default="latest", help= "the version of the dependency app you want to tie this app branch to - use 'latest' to tie to last branched version" ) parser.add_option( "", "--failover", dest="failover", action="store_true", default=False, help="will also deploy acre to the failover version of appengine") parser.add_option( "", "--nosite", dest="nosite", action="store_true", default=False, help= "will not bundle freebase site with acre when deploying to appengine") parser.add_option("-s", "--site", dest="site", default="freebase-site", help="the site you want to work on - one of %s" % ",".join(Site._sites.keys())) parser.add_option( "", "--prevent_overwrite", dest="prevent_overwrite", action="store_true", default=False, help="avoid copying svn checkouts if the directory already exists") #speedtest options parser.add_option("", "--page", dest="page", default=None, help="speedtest: the page you are testing") parser.add_option("", "--test", dest="test", default=None, help="speedtest: the test you want to run") parser.add_option("", "--repeat", dest="repeat", default=10, help="speedtest: number of times the page will be hit", type="int") parser.add_option("", "--host", dest="host", default=None, help="host to hit - just the domain name") parser.add_option("", "--concurrent", dest="concurrent", default=1, help="speedtest: number of concurrent clients", type="int") parser.add_option("", "--list", dest="list", action="store_true", default=False, help="speedtest: list pages and tests") parser.add_option("", "--type", dest="type", default="/type/type", help="freebase type id") parser.add_option("", "--cost", dest="cost", default=ActionSpeedTest.x_cost_default, help="x-metaweb-cost verbosity: %s" % "\n".join(ActionSpeedTest.x_labels_groups.keys())) # Parse the arguments. (options, args) = parser.parse_args() # Figure out the action - one action per call. # There was no action specified here. if not len(args) or args[0] not in [a[0] for a in valid_actions]: parser.error('You did not provide a valid action') exit(-1) action = args[0] context = Context(options) context.set_action(action) for valid_action in valid_actions: if action == valid_action[0]: action_class = valid_action[2] def run(action_class, context): """Run an action given the context.""" context.start_time = datetime.datetime.now() result = None try: result = action_class(context)() finally: t2 = datetime.datetime.now() if not result: context.error( 'FAILED: action %s failed (%s)' % (action, context.duration_human(t2 - context.start_time))) else: context.log( 'SUCCESS: action %s ended succesfully (%s)' % (action, context.duration_human(t2 - context.start_time)), color=context.GREEN) context.set_action(action) return True result = None results = [] context.start_time = datetime.datetime.now() # Loop through each app, resolve version/lib from arguments and run the action with that app. try: if options.app: apps = options.app.split(',') if apps[0] == "all": apps = Site.Get(context).apps() for i, app in enumerate(apps): options.app = app context.set_app( App.Get(context, app, options.version, options.tag)) result = run(action_class, context) results.append(result) else: result = run(action_class, context) results.append(result) except KeyboardInterrupt: context.error("Aborted by user.") except FatalException as ex: context.error(ex.msg) finally: t2 = datetime.datetime.now() acre = Acre.Get(context, existing=True) if acre: acre.stop() if not result or False in results: n = len([x for x in results if not x]) context.error( 'FAILED: action %s failed (%s)' % (action, context.duration_human(t2 - context.start_time))) if n > 1: context.error('%s action%s failed.' % (n, n > 1 and 's' or '')) for reminder in context.reminders: context.log(reminder, 'reminder', color=context.RED)
def __call__(self): print ",".join(Site.Get(self.context).apps()) return True