当前位置: 首页>>代码示例>>Python>>正文


Python moment.date函数代码示例

本文整理汇总了Python中moment.date函数的典型用法代码示例。如果您正苦于以下问题:Python date函数的具体用法?Python date怎么用?Python date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了date函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: computeMatchPosts

def computeMatchPosts(uid, post_content, mydb):

    res = mydb.selectCollection("xmatePost")
    if(res['status']):
        return res

    dis_threshold = 2.0
    match_list = {}
    docu_list = []

    if(post_content["type"] == None):
        pass
    else:
        match_list["type"] = post_content["type"]

    if(post_content["time_range"] == None):
        pass
    else:
        #st = datetime.fromtimestamp(post_content["time_range"]["start_time"])
        st = moment.unix(post_content["time_range"]["start_time"])
        #en = datetime.fromtimestamp(post_content["time_range"]["end_time"])
        en = moment.unix(post_content["time_range"]["end_time"])
        #nst = datetime(st.year, st.month, st.day, 0)
        nst = moment.date(st.year, st.month, st.day, 0).epoch()
        #nen = datetime(st.year, st.month, st.day, 23,59)
        nen = moment.date(st.year, st.month, st.day, 23,59).epoch()
        match_list["time_range.start_time"] = {'$gt': nst}
        #match_list["time_range.end_time"] = {'$lt': datetime.timestamp(nen)}
        match_list["time_range.end_time"] = {'$lt': nen}


    res = mydb.getData(match_list)
    if(res["status"]):
        return res
    cursor = res["content"]

    if(post_content["location"] == None):
        for doc in cursor:
            docu_list.append(doc)
        docu_list.sort(key = lambda postd: postd["post_datetime"], reverse = True)
    else:
        for doc in cursor:
            # if(doc["related_member"].count(uid) > 0):
            #     continue
            dist = calculateDistance(doc["location"], post_content["location"])
            if(dist < dis_threshold):
                doc["diff"] = dist
                docu_list.append(doc)
        docu_list.sort(key = lambda postd: (postd["post_datetime"],postd["diff"]))


    return returnHelper(content = docu_list)
开发者ID:taoalpha,项目名称:XMate,代码行数:52,代码来源:computematch.py

示例2: split_by_month

def split_by_month(collection_name):
    """
    Принимает на входе данные, возвращает массив этих данных, разбитых по месяцам
    """
    min_date = find_min_date(collection_name)
    max_date = find_max_date(collection_name)
    output = []

    while (moment.date(min_date).add(months=1).date < max_date):
        chunk = list(ngs.find({"$and": [{"date": {"$lt": moment.date(min_date).add(months=1).date}}, {"date": {"$gte": min_date}}]}).sort("date", 1))
        output.append((chunk, min_date))
        min_date = moment.date(min_date).add(months=1).date
    # TODO: возвращать не просто массив, а объект, где помимо данных будет их привязка к месяцу
    return output
开发者ID:i-Hun,项目名称:thesis-code,代码行数:14,代码来源:timeseries.py

示例3: test_devices_post_existing

    def test_devices_post_existing(self, mock_moment):
        mock_datetime = moment.utc('2015-06-22', '%Y-%m-%d').timezone(CONFIG['moment']['timezone'])
        mock_moment.side_effect = lambda: mock_datetime

        expected_device = {
            'tipo': 'gcm',
            'id': 'dummy',
            'fecha_registro': moment.date('2015-06-21', '%Y-%m-%d').isoformat()
        }

        Device.insert_one(self.mongo_db, 'gcm', 'dummy')

        response = self.app.post('/0/dispositivos', data={'tipo': 'gcm', 'id': 'dummy'})

        self.assertEqual('application/json', response.mimetype)
        self.assertEqual(200, response.status_code)

        data = json.loads(response.data.decode())

        self.assertEqual(dict, type(data))

        self.assertNotEqual(expected_device['fecha_registro'], data['fecha_registro'])
        del expected_device['fecha_registro']
        del data['fecha_registro']

        self.assertEqual(expected_device, data)
开发者ID:m4droid,项目名称:Restriccion-API,代码行数:26,代码来源:test_api_devices.py

示例4: test_models_device_insert_existing

    def test_models_device_insert_existing(self, mock_moment):
        mock_datetime = moment.utc('2015-06-22', '%Y-%m-%d').timezone(CONFIG['moment']['timezone'])
        mock_moment.side_effect = lambda: mock_datetime

        expected_data = {
            'tipo': 'email',
            'id': '[email protected]',
            'fecha_registro': mock_datetime.isoformat()
        }

        Device.insert_one(self.mongo_db, 'email', '[email protected]')

        # Mock new date
        mock_datetime = moment.date('2015-06-23', '%Y-%m-%d')
        mock_moment.side_effect = lambda: mock_datetime

        response = Device.insert_one(self.mongo_db, 'email', '[email protected]')

        self.assertEqual(1, self.mongo_db.devices.count())
        device_in_db = self.mongo_db.devices.find_one({'tipo': 'email', 'id': '[email protected]'}, {'_id': 0})
        self.assertEqual(expected_data, device_in_db)

        # Keep previous data
        self.assertEqual('ok', response['status'])
        self.assertEqual(expected_data, response['data'])
开发者ID:m4droid,项目名称:Restriccion-API,代码行数:25,代码来源:test_models_device.py

示例5: manage

def manage(request):
    page = request.GET.get('page', 1)
    per_page = request.GET.get('PerPage', 10)

    plan_list = Plan.objects.filter(user=request.user).order_by('-created_at') 
    paginator = Paginator(plan_list, per_page) 
    
    counts = plan_list.count()
    next_per_page = int(per_page) + 10
    if int(per_page) > counts:
        next_per_page = 0
     

    try:
        plans = paginator.page(page)
    except PageNotAnInteger:
        plans = paginator.page(1)
    except EmptyPage:
        plans = paginator.page(paginator.num_pages)
    
    precent_list = map(clac_plan_percent, plans)

    for i, plan in enumerate(plans):
        plan.precent =  precent_list[i]

        to_moment = moment.date(plan.created_at)
        plan.format_time = to_moment.format("YYYY.MM.DD")
        plan.weekday = get_format_weekday(to_moment.weekday)

    return render(request, 'manage.html',
            {'title': '管理规划', 'plans': plans, 'next_per_page': next_per_page})
开发者ID:zhengxiaowai,项目名称:meiruguihua,代码行数:31,代码来源:views.py

示例6: parse_178_html

def parse_178_html(html):
	soup = BeautifulSoup(html, 'lxml')
	dls = soup.find_all('div', attrs={'class': 'list-section'})
	items = []
	for dl in dls:
		try:
			data = {}
			simgtag = dl.find('div', attrs={'class': 'list-section-image'})
			if simgtag:
				data['img'] = simgtag.find('a').attrs['href']
			ctag = dl.find('div', attrs={'class': 'list-section-contents'})
			if ctag:
				htag = ctag.find('h2')
				atag = htag.find('a')
				data['href'] = atag.attrs['href']
				data['id'] = md5.new(data['href']).hexdigest()
				data['title'] = atag.attrs['title']
				data['created_at'] = moment.date(ctag.find('h5').text.split('.')[0], 'YYYY-MM-DD HH:mm:ss').format('YYYY-MM-DDThh:mm:ss')
				data['text'] = ctag.find('p').text
				items.append(data)
		except Exception, e:
			raise
		else:
			pass
		finally:
开发者ID:DangDangSister,项目名称:kandota,代码行数:25,代码来源:parser.py

示例7: batchTasks

def batchTasks(username, repository, service):
    """
	Fetches all issues for the given user in a repository from
	the specified service
	"""
    if service == "github":
        issues = requests.get(
            "https://api.github.com/repos/"
            + username
            + "/"
            + repository
            + "/issues?client_id=f4c46f537e5abec0d5b0&client_secret=53ba628c38e4f8adca7d467573a13989b4546743"
        )
        data = json.loads(issues.text)
        print len(data)
        # print 'https://api.github.com/repos/' + username + '/' + repository + '/issues?state=all&client_id=f4c46f537e5abec0d5b0&client_secret=53ba628c38e4f8adca7d467573a13989b4546743'

        # Store all the User data (will be posted to Todoist)
        users = []

        for datum in data:
            user = {}
            if datum["assignee"] != None:
                if datum["assignee"]["login"] == username:
                    user["username"] = datum["assignee"]["login"]
                    user["title"] = datum["title"]
                    if datum["milestone"] != None:
                        m = moment.date(datum["milestone"]["due_on"], "%Y-%m-%dT%H:%M:%SZ")
                        user["due"] = m.format("YYYY-M-D H:M")
                    users.append(user)
        return users
    else:
        data = batchBitbucketTasks(username, repository)
        return data
开发者ID:DrkSephy,项目名称:hacker-todoist,代码行数:34,代码来源:issues.py

示例8: get_scatter_data

def get_scatter_data(timespan):
    """Send tweet sentiment to scatter plot"""
    print "In our JSON route" + session.get("ticker")
    ticker = session.get("ticker")
    current_stock = Stock.query.get(ticker)
    tweets = current_stock.get_tweets()
    stocks = Stock.query.all()

    # tweets_json = json.dumps(tweets, default=lambda o: o.__dict__)

    # now = moment.utcnow().timezone("US/Eastern")
    result = []
    s = Sentiment(stocks)
    sentiment = None
    negative = ['0.0', '0.1', '0.2', '0.3', '0.4', '0.5']
    positive = ['0.6', '0.7', '0.8', '0.9', '1.0']

    for tweet in tweets:
        #create a moment that represents now - 24 hours
        day_ago = moment.utcnow().timezone("US/Eastern").subtract(hours=24)
        # convert unicode created_at to string
        created_at = unicodedata.normalize('NFKD', tweet.created_at).encode('ascii', 'ignore')
        # format created_at string to ISO 8610
        created_at_str = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y'))
        # create a moment from the string
        created_at = moment.date(created_at_str, 'YYYY-MM-DD HH:mm:ss')
        # convert timezone of moment from UTC to Eastern time
        created_at_final = created_at.utcnow().timezone("US/Eastern")
        print created_at_final > day_ago
        if tweet.text.count('$') == 1 and tweet.retweeted_status is None and created_at_final > day_ago:
            # Convert tweet text from unicode to text
            tweet_text = unicodedata.normalize('NFKD', tweet.text).encode('ascii', 'ignore')
            # Get the sentiment of the tweet retured in either 'positive' or 'negative'
            sentiment_str = s.get_tweet_sentiment(tweet_text)
            if sentiment_str == 'positive':
                sentiment = random.choice(positive)
            if sentiment_str == 'negative':
                sentiment = random.choice(negative)
            created_at = unicodedata.normalize('NFKD', tweet.created_at).encode('ascii', 'ignore')
            # Sun Jun 05 17:09:07 +0000 2016
            created_at_str = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y'))
            # Below 4 lines returns duplicate timestamps... need a way to convert to US/EST timezone
            # create a moment from the string
            # created_at = moment.date(created_at_str, 'YYYY-MM-DD HH:mm:ss')
            # convert timezone of moment from UTC to Eastern time
            # created_at_final = created_at.utcnow().timezone("US/Eastern")
            print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
            print created_at_str
            print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
            result.append({'datetime': created_at_str, 'sentiment': sentiment})
    #sort dictionary by datetime
    sorted_result = sorted(result, key=lambda k: k['datetime'])
    return json.dumps(sorted_result)
开发者ID:lachilles,项目名称:BullishTweets,代码行数:53,代码来源:server.py

示例9: reports_get_query

def reports_get_query():
    date = request.args.get('fecha')

    query = {}

    if date is not None:
        try:
            query['fecha'] = moment.date(date.strip(), '%Y-%m-%d').format('YYYY-M-D')
        except ValueError:
            return None

    return query
开发者ID:m4droid,项目名称:Restriccion-API,代码行数:12,代码来源:wsgi.py

示例10: show_search_results

def show_search_results():
    """Search Twitter and return a dictionary of results."""

    #Get values from search-box via AJAX
    current_keyword = request.form.get('search').lower()
    print "**********************"
    print current_keyword
    print "**********************"
    tweets = get_tweets_by_api(term=current_keyword)

    result = []

    for tweet in tweets:
        # Exclude retweets since they appear as duplicatses to endu ser
        if tweet.retweeted_status is None:
            # Convert tweet text from unicode to text
            tweet_id = tweet.id
            text = unicodedata.normalize('NFKD', tweet.text).encode('ascii', 'ignore')
            # Find URL in text and bind to url
            # url = re.search('((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))', text)
            url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', text)
            # Remove URL from text
            text_wo_url = re.sub(r'^https?:\/\/.*[\r\n]*', '', text, flags=re.MULTILINE)
            # Handle / Name
            user = unicodedata.normalize('NFKD', tweet.user.screen_name).encode('ascii', 'ignore')
            # Count of favorites
            favorite_count = tweet.favorite_count
            #Return dictionary of hashtags with hashtag as key and number of occurances as value
            if tweet.hashtags:
                # Convert hashtags from unicode to string
                ht_list = []
                for hashtag in tweet.hashtags:
                    ht_str = unicodedata.normalize('NFKD', hashtag.text).encode('ascii', 'ignore')
                    ht_list.append(ht_str.lower())
                hashtags = Counter(ht_list)
            else:
                hashtags = tweet.hashtags
            # Convert tweet from unicode to datetime
            created_at = tweet.created_at
            # format created_at string to ISO 8610
            created_at_str = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y'))
            # create a moment from the string
            created_at = moment.date(created_at_str, 'YYYY-MM-DD HH:mm:ss')
            result.append({'created_at': created_at_str, 'tweet_text': text_wo_url, 'user': user,
                           'favorite_count': favorite_count, 'hashtags': hashtags,
                           'url': url, 'tweet_id': tweet_id})

    print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
    print result
    print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"

    return jsonify(result=result)  #, tweets
开发者ID:lachilles,项目名称:TwitterSearch,代码行数:52,代码来源:server.py

示例11: processvote

 def processvote(self, answer_selected, request):
     new_vote = Vote.objects.create(voter=None, answer=answer_selected)
     if request.user.is_authenticated():
         user = request.user
         new_vote.voter = user
         # answer_selected.selected_by.add(user)
         # self.answered_by.add(user)
     new_vote.date = moment.date(datetime.datetime(new_vote.created.year,new_vote.created.month,new_vote.created.day)).epoch()
     new_vote.date = long(str(long(new_vote.date))+"000")
     new_vote.save()
     answer_selected.save()
     self.save()
     return self
开发者ID:Pavit,项目名称:pollaboration_project,代码行数:13,代码来源:models.py

示例12: adminChargeMonthcard

 def adminChargeMonthcard(self, face, user_id = None, user_qq = None, administrator_id = None, administrator_qq = None):
     """
     date object: end date
     1: face not valid
     2: user not exist
     100: system error
     """
     card_item = self.getMonthcard(face)
     if not card_item:
         return 1
     if not self.long_connect: self.connect()
     user = self.getUser(user_id, user_qq, no_insert = True)
     administrator = self.getUser(administrator_id, administrator_qq)
     if not user: 
         if not self.long_connect: self.close(False)
         return 2
     if not administrator:
         logging.warning("<detected error> administrator not found")
         if not self.long_connect: self.close(False)
         return 100
     now_timestamp = self.timestamp()
     today = self.datetime(now_timestamp)
     today = moment.date(today.year, today.month, today.day).date
     start_timestamp = self.timestamp(today)
     if self.cur.execute('SELECT time_end FROM monthcard WHERE user_id = {0} AND face = "{1}" ORDER BY time_end DESC LIMIT 1'.format(user.id, face)):
         record = self.cur.fetchone()
         if record[0] > start_timestamp: start_timestamp = record[0]
     start_time = self.datetime(start_timestamp)
     start_time = moment.date(start_time.year, start_time.month, start_time.day)
     end_time = start_time.clone().add(months = 1).date
     start_time = start_time.date
     start_timestamp = self.timestamp(start_time)
     end_timestamp = self.timestamp(end_time)
     if not self.cur.execute('INSERT INTO monthcard (user_id, administrator_id, face, time_register, time_start, time_end) VALUES ({0}, {1}, "{2}", {3}, {4}, {5})'.format(user.id, administrator.id, face, now_timestamp, start_timestamp, end_timestamp)):
         logging.warning("<detected error> insert monthcard record not found")
         if not self.long_connect: self.close(False)
         return 100
     if not self.long_connect: self.close(True)
     return datetime.date.fromtimestamp(end_timestamp/1000)
开发者ID:qqbot-pet-game,项目名称:petgame-mojobot,代码行数:39,代码来源:GameUtil.py

示例13: is_good_tweet

def is_good_tweet(tweet):
    """Ignore tweets with more than 1 $ symbol, retweets, and anything older than 1 day"""
    #create a moment that represents now - 24 hours
    day_ago = moment.utcnow().timezone("US/Eastern").subtract(hours=24)
    # convert unicode created_at to string
    created_at = unicodedata.normalize('NFKD', tweet.created_at).encode('ascii', 'ignore')
    # format created_at string to ISO 8610
    created_at_str = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y'))
    # create a moment from the string
    created_at = moment.date(created_at_str, 'YYYY-MM-DD HH:mm:ss')
    # convert timezone of moment from UTC to Eastern time
    created_at_final = created_at.utcnow().timezone("US/Eastern")
    print created_at_final > day_ago
    return tweet.text.count('$') == 1 and tweet.retweeted_status is None and created_at_final > day_ago
开发者ID:lachilles,项目名称:BullishTweets,代码行数:14,代码来源:seed.py

示例14: details

def details(request, plan_id):
    plan = Plan.objects.get(id=plan_id)
    to_moment = moment.date(plan.created_at)
    format_time = to_moment.format("YYYY.MM.DD")
    weekday = get_format_weekday(to_moment.weekday)
    precent =  clac_plan_percent(plan)

    plan_details = PlanDetail.objects.filter(plan=plan)
    

    return render(request, 'details.html',{'title': '详情',
        'details': plan_details,
        'note': plan.note,
        'date': format_time,
        'precent': precent,
        'weekday': weekday})
开发者ID:zhengxiaowai,项目名称:meiruguihua,代码行数:16,代码来源:views.py

示例15: test_devices_post_ok

    def test_devices_post_ok(self, mock_moment):
        mock_datetime = moment.date('2015-06-22', '%Y-%m-%d')
        mock_moment.side_effect = lambda: mock_datetime

        expected_device = {'tipo': 'gcm', 'id': 'dummy'}

        response = self.app.post('/0/dispositivos', data=expected_device)

        self.assertEqual('application/json', response.mimetype)
        self.assertEqual(200, response.status_code)

        data = json.loads(response.data.decode())

        self.assertEqual(dict, type(data))

        expected_device['fecha_registro'] = mock_datetime.isoformat()
        self.assertEqual(expected_device, data)
开发者ID:m4droid,项目名称:Restriccion-API,代码行数:17,代码来源:test_api_devices.py


注:本文中的moment.date函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。