コード例 #1
0
ファイル: core.py プロジェクト: carriercomm/HelloSpaceBot
def main(post):
	#master process should randomize a mission choice and page choice.
	#should check against "pages done" list at some point

	choosenCraft = utils.weighted_choice(config.CRAFT_LIST)

	photos = getImagesList(choosenCraft['craft'], random.randint(1, choosenCraft['pages']))
	imgObj = selectRandImage(photos)
	text = None

	if 'not_found' not in imgObj['url'] or 'http' not in imgObj['url']:
		missionDataObj = getMissionData(imgObj['ring_obs_id'])
		text = writePostText(missionDataObj, choosenCraft['craft'])
	

	if post is False and text is not None:
		print imgObj['ring_obs_id']+" -> "+imgObj['url']
		print utils.striphtml(text['post'])
	elif text is not None:
		print imgObj['url']
		print utils.striphtml(text['post'])
		postToTumblr(imgObj['url'], text, choosenCraft['craft'])
	else:
		print 'Error while generating post for'+imgObj['ring_obs_id']+'.\nSkipping.'
	
		
	print '\n----------------------\n'
コード例 #2
0
def gTrans(query, destlanguage='en', prompterror=True):
    log.info(
        "Using Google translate to determine the unknown translation of %s",
        query)

    # No meanings if we don't have a query
    if query == None:
        return None

    # No meanings if our query is blank after stripping HTML out
    query = utils.striphtml(query)
    if query.strip() == u"":
        return None

    try:
        # Return the meanings (or lack of them) directly
        return lookup(query, destlanguage)
    except urllib2.URLError, e:
        # The only 'meaning' should be an error telling the user that there was some problem
        log.exception("Error while trying to obtain Google response")
        if prompterror:
            return [[
                Word(Text('<span style="color:gray">[Internet Error]</span>'))
            ]]
        else:
            return None
コード例 #3
0
ファイル: core.py プロジェクト: carriercomm/HelloSpaceBot
def writePostText(missionData, spacecraft):
	#Use mission data to generate the text posted with the picture 
	#Mission Name, Target Photographed, Date, Instrument, OPUS link

	source = 'http://pds-rings-tools.seti.org/opus#/ringobsid='+missionData['ring_obs_id']+'&detail='+missionData['ring_obs_id']+'&view=detail'
	#print missionData['ring_obs_id']
	if missionData['target_name'] is None:
		return None

	post = 'A photo of <b>'+missionData['target_name'].title()+'</b>'
	if missionData['target_class'] != 'PLANET':
		if missionData['target_class'][0] in 'aeiou':
			post += ', an '
		else:
			post += ', a '
		post += missionData['target_class'].lower()

		if missionData['planet_id'] is not None:
			if missionData['target_class'] == 'MOON':
				post += ' of <b>'+config.PLANET_ID_TABLE[missionData['planet_id']]+'</b>'
			else:
				post += ' near <b>'+config.PLANET_ID_TABLE[missionData['planet_id']]+'</b>'


	post += '.'
	tweet = utils.striphtml(post)
	post+= '<br />\n'
	post += 'Took by <b>'+spacecraft+'</b> with '+missionData['instrument_id']

	if missionData['time1'] is not None and missionData['time1'] != '00:00:00':
		#print("time is not None, time is "+missionData['time1'])
		missionDate = missionData['time1'].replace("-", "").split(".")[0]
		try:
			date = time.strptime(missionDate, "%Y%m%dT%H:%M:%S")
		except ValueError:
			try:
				date = time.strptime(missionDate, "%Y%jT%H:%M:%S")
			except ValueError:
				print 'Time is invalid: '+missionData['time1']
			else:
				post += ' on ' + time.strftime("%B %d, %Y at %H:%M:%S", date)
		else:
			post += ' on ' + time.strftime("%B %d, %Y at %H:%M:%S", date)

	post += '.<br />\n'
	post += '<br />\n'

	post += '<a href="'+source+'" target="_blank">'
	post += 'Detail page on OPUS database.</a>'


	return {'post':post, 'tweet':tweet, 'source':source }
コード例 #4
0
def gTrans(query, destlanguage='en', prompterror=True):
    log.info("Using Google translate to determine the unknown translation of %s", query)

    # No meanings if we don't have a query
    if query == None:
        return None
    
    # No meanings if our query is blank after stripping HTML out
    query = utils.striphtml(query)
    if query.strip() == u"":
        return None

    try:
        # Return the meanings (or lack of them) directly
        return lookup(query, destlanguage)
    except urllib2.URLError, e:
        # The only 'meaning' should be an error telling the user that there was some problem
        log.exception("Error while trying to obtain Google response")
        if prompterror:
            return [[Word(Text('<span style="color:gray">[Internet Error]</span>'))]]
        else:
            return None
コード例 #5
0
ファイル: views.py プロジェクト: 0-1-0/marketbot
 def get_msg(self):
     return (u'<a href="' + self.img + u'">' + self.name + u'</a>\n' + striphtml(self.description))[:500]
コード例 #6
0
ファイル: views.py プロジェクト: 0-1-0/marketbot
 def get_msg(self):
     return (u'<a href="' + self.img + u'">' + self.name + u'</a>\n' +
             striphtml(self.description))[:500]