Changeset - a176c4de6bc8
[Not reviewed]
default
0 1 0
Dennis Fink - 7 years ago 2018-02-10 13:59:26
dennis.fink@c3l.lu
Add more possivle tweets
1 file changed with 8 insertions and 0 deletions:
0 comments (0 inline, 0 general)
spaceapi/utils.py
Show inline comments
 
@@ -11,56 +11,61 @@ import tweepy
 

	
 
default_json_file = os.path.abspath('default.json')
 
last_state_file = os.path.abspath('laststate.json')
 

	
 
default_json_file_v14 = os.path.abspath('default_v14.json')
 
last_state_file_v14 = os.path.abspath('laststate_v14.json')
 

	
 
if not os.path.exists(default_json_file):
 
    raise RuntimeError('default.json does not exists!')
 
elif not os.path.isfile(default_json_file):
 
    raise RuntimeError('default.json is not a file!')
 

	
 
if not os.path.exists(default_json_file_v14):
 
    raise RuntimeError('default_v14.json does not exists!')
 
elif not os.path.isfile(default_json_file):
 
    raise RuntimeError('default_v14.json is not a file!')
 

	
 

	
 
possible_open_tweets = (
 
    'The space is now open!',
 
    'The space is open! Come in and hack something!',
 
    'Yes, we\'re open! Come in and create something!',
 
    'Come by and hack something! We\'ve just opened!',
 
    'The ChaosStuff is now open for everyone!',
 
    'Let the Chaos begin! We\'re open!',
 
    'What do we hack now? Come and see, we\'ve just opened!',
 
    'TUWAT! Come and hack. We are open!',
 
)
 

	
 
possible_closed_tweets = (
 
    'The space is now closed!',
 
    'We\'re closed now! See you soon.',
 
    'Sorry, we are closed now!',
 
    'The ChaosStuff is now closed! Come back another time!',
 
    'Poweroff process finished! We\'re closed!',
 
    'Singularity reached! The space is closed!',
 
    'Dream of electric sheeps! We are closed!',
 
)
 

	
 

	
 
def post_tweet(tweet, spaceapi=None):
 
    if 'TWITTER_CONSUMER_KEY' in current_app.config:
 
        auth = tweepy.OAuthHandler(
 
            current_app.config['TWITTER_CONSUMER_KEY'],
 
            current_app.config['TWITTER_CONSUMER_SECRET']
 
        )
 
        auth.set_access_token(
 
            current_app.config['TWITTER_ACCESS_TOKEN_KEY'],
 
            current_app.config['TWITTER_ACCESS_TOKEN_SECRET']
 
        )
 
        api = tweepy.API(auth)
 
        if spaceapi is None:
 
            api.update_status(tweet)
 
        else:
 
            api.update_status(tweet, lat=spaceapi['location']['lat'], lon=spaceapi['location']['lon'])
 

	
 

	
 
class Singleton:
 

	
 
    def __new__(cls, *args, **kwargs):
 
        key = str(hash(cls))
 
@@ -165,48 +170,51 @@ class ActiveStatus(Singleton, dict):
 
            if not value:
 
                if 'people_now_present' in self['sensors']:
 
                    self.clear_user_present()
 

	
 
                if 'message' in self['state']:
 
                    del self['state']['message']
 

	
 
            if trigger_person is None:
 
                del self['state']['trigger_person']
 
            else:
 
                self['state']['trigger_person'] = trigger_person
 

	
 
            self['state']['lastchange'] = int(time())
 

	
 
        if message is not None:
 
            self['state']['message'] = message
 

	
 

	
 
class ActiveStatusv14(ActiveStatus):
 

	
 
    def __init__(self):
 
        self.default_json_file = default_json_file_v14
 
        self.last_state_file = last_state_file_v14
 

	
 
    def send_tweet(self, value):
 
        pass
 

	
 

	
 
def request_wants_json():
 
    best = request.accept_mimetypes.best_match(
 
        ['application/json', 'text/html']
 
    )
 
    return best == 'application/json' and \
 
        request.accept_mimetypes[best] > \
 
        request.accept_mimetypes['text/html']
 

	
 

	
 
def fuzzy_list_find(lst, key, value):
 

	
 
    for i, dic in enumerate(lst):
 
        if dic[key] == value:
 
            return i
 

	
 
    raise ValueError
 

	
 

	
 
def first(iterable, keys):
 
    for key in keys:
 
        if key in iterable:
 
            return key
 

	
0 comments (0 inline, 0 general)