Twitter Search API - Searching by Time - search

Is there any way to send a query param to Twitter, telling it to only return search results within a specified period of time? For example, give me the results for this "keyword" tweeted between 12 pm and 3 pm ET on July 24, 2011? If Twitter doesn't allow you to search by time -- and only by date -- then is there anything in the results that will allow you to see the exact time when the user made that tweet?

As far as I can tell, there is not a way to specify time (more specific than the date). However, after getting your list of tweets, you can remove those that don't fall within the specified time range by comparing each tweet's timestamp.
This is how I would do it in ruby with the twitter gem:
require 'twitter'
require 'time'
start_time = Time.now - 3*3600
end_time = Time.now
search = Twitter::Search.new.contains('test')
search.since_date(start_time.strftime("%Y-%m-%d"))
search.until_date(end_time.strftime("%Y-%m-%d"))
tweets = search.fetch
tweets.delete_if { |t| Time.parse(t.created_at) < start_time }
tweets.delete_if { |t| Time.parse(t.created_at) > end_time }

Related

Noda time comparisons between zoned datetime and instant

I am writing a function to test if a file creation time is before the start of the current day in a different time zone, and fetch if my local file copy is stale.
Checking here Noda Time - Start/end of day with zone I have come up with the below:
bool FileCreationIsBeforeStartOfDayInNewYork()
{
var zone = DateTimeZoneProviders.Tzdb["America/New_York"];
var nowInNewYork = SystemClock.Instance.InZone(zone).GetCurrentZonedDateTime();
var today = nowInNewYork.Date;
var startOfDay = zone.AtStartOfDay(today);
var fileCreationTime = ZonedDateTime.FromDateTimeOffset(File.GetLastWriteTime(Filename).ToUniversalTime());
return fileCreationTime.ToInstant() < startOfDay.ToInstant();
}
The File.GetLastWriteTime method returns the file modification time of the local system clock.
I am confused if I should be converting the file creation time to the systems local time or if stick with UTC, and if my use of ToInstant is correct in this context?

How can I select all items from the DB on a week period usign SQLALCHEMY (Flask)

So I was wondering if there is a way to get a week or month period from DB. I have in my DB a value and a date and I want to get all items that their date are between for example 2020-03-01 and 2020-04-01.
I tried the following code but it gives a warning and doesn't return nothing:
The code:
users_count = StatsUsers.query.filter(and_(func.date(StatsUsers.created_date >= '2020-03-30'), func.date(StatsUsers.created_date <= '2020-04-30')))
for x in users_count:
print(x.value)
return render_template('admin/index.html', users_count=0)
The warning that it gives:
Warning: (1292, "Incorrect datetime value: '1'")
My DB:
I fixed my issue after reading this post:
Flask-sqlalchemy query datetime intervals
What I did was basically change the filter(and_(func.date())) to only filter() and making sure the DB was in DATETIME.
The new code:
users_count = StatsUsers.query.filter(StatsUsers.created_date >= '2020-03-01 00:00:00').filter(StatsUsers.created_date <= '2020-04-30 00:00:00').all()
for x in users_count:
print(x.value)

How to call a function every interval time Odoo 11

i know we can create automatic action using cron in odoo
but I want something a different
in the mass mailing of odoo i want to add a repetion option of mail mass mailings
Example in the Form view_mail_mass_mailing_form > Options page
I added a repetition selection field,
I added this because I want each mass mail alone
class MailMassMailing(models.Model):
_inherit = 'mail.mass_mailing'
recurrence_mail = fields.Selection([
('daily', 'Day'),
('weekly', 'Weeks'),
('monthly', 'Months'),
], string='Recurring')
I want this mass mailng to send each (days or weeks or months)
how to call a function with interval date,
how to call a function every (days or weeks or months)
The sending of this mass mailing is revived from the date of creation
Just extend Mass Mailing model with a new date field and implement a model method to use for a daily running ir.cron.
from odoo import api, fields, models
class MailMassMailing(models.Model):
_inherit = 'mail.mass_mailing'
recurrence_mail = fields.Selection([
('daily', 'Day'),
('weekly', 'Weeks'),
('monthly', 'Months'),
], string='Recurring')
last_sent_on = fields.Date()
#api.model
def run_send_recurring(self):
""" Resend mass mailing with recurring interval"""
domain = [('recurrence_mail', '!=', False)]
# TODO monthly should be solved in another way, but that
# is not needed for this example
deltas = {'daily': 1, 'weekly': 7, 'monthly': 30}
today = fields.Date.today()
for mass_mail in self.search(domain):
# never sent? go send it
if not mass_mail.last_sent_on:
# send the way you want
# or get delta between today and last_sent_on
last_dt = fields.Date.from_string(mass_mail.last_sent_on)
if (today - last_dt).days >= deltas[mass_mail.recurrence_mail]:
# send the way you want
Thank you #CZoellner for your help
I found the solution with your idea
# Solution ############### .py
#api.model
def run_send_recurring(self):
""" Resend mass mailing with recurring interval"""
date_format = '%Y-%m-%d'
domain = [('recurrence_mail', '!=', False),('state','=','done')]
deltas = {'daily': 1, 'weekly': 7, 'monthly': 30}
logger.info("______deltas________: %s ",deltas)
today = fields.Date.today()
logger.info("______today________: %s ",today)
for mass_mail in self.search(domain):
logger.info("______mass_mail________: %s ",mass_mail)
# never sent? go send it
if not mass_mail.last_sent_on:
self.put_in_queue()
joining_date = mass_mail.last_sent_on
current_date = (datetime.today()).strftime(date_format)
print('joining_date',joining_date)
d1 = datetime.strptime(joining_date, date_format).date()
logger.info("______1 day________: %s ",d1)
d2 = datetime.strptime(current_date, date_format).date()
logger.info("______2 day________: %s ",d2)
logger.info("______deltas[mass_mail.recurrence_mail]________: %s ",deltas[mass_mail.recurrence_mail])
r = relativedelta(d1,d2)
logger.info("______r day________: %s ",r.days)
if (r ,'>=' , deltas[mass_mail.recurrence_mail]):
mass_mail.put_in_queue()

check availability of meeting rooms in outlook with python

I am working on to write a python script to check if particular meeting room is available. If yes then meeting room will be booked, if not then python will find available time slot for that day.
For now, I have achieved to book meeting room but I am not able to check availability of rooms.
To book any meeting room, i have to send mail to that book meeting room configured mail id and corresponding acceptance/decline mail I receive as per the availability.
below is the snippet :
import win32com.client
import datetime
import pywintypes
oOutlook = win32com.client.Dispatch("Outlook.Application")
appt = oOutlook.CreateItem(1)
appt.Start = '2018-05-18 13:30'
appt.Subject = 'Follow Up Meeting'
appt.Duration = 30
appt.Location = '<name of meeting room>'
appt.MeetingStatus = 1
myRecipient = appt.Recipients.Add("<mail id of meeting room")
myRecipient.resolve
my_date = datetime.date(2018,5,18)
pywintypeDate = pywintypes.Time (my_date)
availabilityInfo = myRecipient.FreeBusy(pywintypeDate,30,True)
print(availabilityInfo)
# appt.Save()
# appt.Send()
# print("done")
output is :
000000000000000000000222222200222222022000000000000000000000000000000002222222222220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000002220002222200000000000000000000000000000000002220022022222000000000000000000000000000000000000000000002222000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000222222200000000000000000000000000000000002220000022000000000000000000000000000000000000002220000222222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000002220022022200000000000000000000000000000000000022000022000000000000000000000000000000000000000000000002222000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000022022200000000000000000000000000000000002220002222000000000000000
so is it first byte (0) indicate time slot from 00:00 to 00:30 and soon for one complete month ?
Is it possible to get output only for one day ?
Do i have to parse the above output to check availability for my particular required time ?
appt.Recipients.Add returns the Recipient object. Resolve it first (Recipient.Resolve), then call Recipient.FreeBusy.

Match an approaching date In Lua

I'm looking for a little help on a Lua script. Essentially I'm looking to match an approaching date X number of minutes prior to today. In the example below I've used 9000 minutes.
alarm.get ()
message = "Certificate Expiry Warning - Do something"
SUPPKEY = "Certificate Expiry"
SUBSYS = "1.1"
SOURCE = "SERVERNAME"
--local pattern = "(%d-%m-%Y)"
local t = os.date('*t'); -- get current date and time
print(os.date("%d-%m-%Y")); --Prints todays date
t.min = t.min - 9000; -- subtract 9000 minutes
--print(os.date("%Y-%m-%d %H:%m:%S", os.time(t))); --Original Script
print(os.date("%d-%m-%Y", os.time(t))); --Prints alerting date
if string.match ~=t.min --Match string
--if string.match(a.message, pattern)
--then print (al.message)
then print ("We have a match")
--then nimbus.alarm (1, message , SUPPKEY , SUBSYS , SOURCE) --Sends alert
else print ("Everything is fine") --Postive, no alert
--else print (al.message)
end
The alarm.get grabs a line of text that looks like this:
DOMAIN\USERNAME,Web Server (WebServer),13/01/2017 09:13,13/01/2019,COMPANY_NAME,HOSTNAME_FQDN,SITE
So the line shown above is passed as an a.message variable and I'm looking to match the date highlighted in bold to today's date with 9000 minutes taken off it.
The commented out parts are just me testing different things.
I'm not sure if I understood the question well, but from my perspective it seems you are trying to do two things:
Retrieve current time minus 9000 minutes in format DD/MM/YYYY.
Compare this time to the one your program reads from file and do something, when the two dates are equal.
Here goes my sample code:
-- Settings
local ALLOWED_AGE = 9000 -- In minutes
-- Input line (for testing only)
local inputstr = "DOMAIN\\USERNAME,Web Server (WebServer),13/01/2017 09:13,13/01/2019,COMPANY_NAME,HOSTNAME_FQDN,SITE"
-- Separate line into 7 variables by token ","
local path, server, time, date, company_name, hostname, site = string.match(inputstr, "([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)")
-- Check, if the line is ok (not necessary, but should be here to handle possible errors)
-- Also note, some additional checks should be here (eg. regex to match DD/MM/YYYY format)
if date == nil then
print("Error reading line: "..inputstr)
end
-- Get current time minus 9000 minutes (in format DD/MM/YYYY)
local target_date = os.date("%d/%m/%Y", os.time() - ALLOWED_AGE * 60)
-- Printing what we got (for testing purposes)
print("Target date: "..target_date..", Input date: "..date)
-- Testing the match
if target_date == date then
print("Dates are matched!")
else
print("Dates are not matched!")
end
Although I'm not sure, whether you shouldn't be instead checking for "one date is bigger/smaller then the other" in your case.
Then the code above should be modified to something like this:
-- Extract day, month and year from date in format DD/MM/YYYY
local d, m, y = string.match(date, "([^/]+)/([^/]+)/([^/]+)")
-- Note I'm adding one day, so the certificate will actually expire day after it's "valid until" date.
local valid_until = os.time({year = y, month = m, day = d + 1})
local expire_time = os.time() - ALLOWED_AGE * 60 -- All certificates older than this should expire.
-- Printing what we got (for testing purposes)
print("Expire time: "..expire_time..", Cert valid until: "..valid_until)
-- Is expired?
if valid_until <= expire_time then
print("Oops! Certificate expired.")
else
print("Certificate date is valid.")
end

Resources