Exclude Retweets using LinqToTwitter - twitter

My LinqToTwitter class can not exclude retweets.
var srch = (from search in twitterCtx.Search where search.Type == SearchType.Search && search.Query == term && search.Count == 100 select search).SingleOrDefault();
There is no option about search.IncludeRetweets==false.
How can I do a search with that? Should I try another class?

The Twitter API doesn't offer that option, so neither does LINQ to Twitter. That said, here's what you can do:
Perform your search query as normal. It will contain retweets.
Perform a LINQ to Objects query on the results using a where clause that sets the condition of RetweetedStatus.StatusID == 0, like this:
var nonRetweetedStatuses =
(from tweet in searchResponse.Statuses
where tweet.RetweetedStatus.StatusID == 0
select tweet)
.ToList();
The reason why I suggested using the where clause like this is because LINQ to Twitter instantiates a Status for RetweetedStatus, regardless of whether it exists or not. However, the contents of that Status are the default values of each properties type. Since StatusID will never be 0 for a valid retweet, this works. You could also filter on another field like Text == null and it would still work.

Just add to your search term exclude:replies and/or exclude:retweets:
term = term + " exclude:replies exclude:retweets";

Related

Is it possible to search Twitter Users by number of followers?

I would like to find public users on Twitter that have 0 followers. I was thinking of using https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search, but this doesn't have a way to filter by number of followers. Are there any simple alternatives? (Otherwise, I might have to resort to using a graph/search based approach starting from a random point)
Well you didn't specify what library you are using to interact with the Twitter API. But regardless of which technology you're using, the underlying concept is the same. I will use tweepy library in python for my example.
Start by getting the public users using this. The return type is a list of user objects. The user object has several attributes which you can learn about here. For now we are interested in the followers_count attribute. Simply loop through the objects returned and check where the value of this attribute is 0.
Here's how the implementation would look like in python using tweepy library;
search_query = 'your search query here'
get_users = api.search_users(q = search_query)#Returns a list of user objects
for users in get_users:
if users.followers_count ==0:
#Do stuff if the user has 0 followers
Bird SQL by Perplexity AI allows you to do this simply: https://www.perplexity.ai/sql
Query: Users with 0 followers, and 0 following, with at least 5 tweets
SELECT user_url, full_name, followers_count, following_count, tweet_count
FROM users
WHERE (followers_count = 0)
AND (following_count = 0)
AND (tweet_count >= 5)
ORDER BY tweet_count DESC
LIMIT 10

ActiveRecord select by last character of string

I tried
members = Member.select(:member_id[6] == "1")
and
members = Member.select(member_id[6]: == "1")
and
members = Member.select("member_id[6]" == "1")
I am trying to get only those members where their member_id final character is a 1.
To get what you want, efficiently, you'll need to leverage Postgres' string functions in a literal SQL condition. Your existing code is also confusing select, the Active Record method that alters what the query uses in its SELECT clause, with select, the Ruby Enumerable method, which allows you to filter a collection. Since your filtering is best performed in the database, you'll want to instead use where.
So, something like:
Member.where("RIGHT(member_id::varchar, 1) = '1'")

Boolean AND logic in Microsoft Dynamics AX 2012 AIF QueryCriteria

According to the documentation:
The system uses Boolean OR logic to connect all the tags.
Does this mean that it is entirely impossible to construct a QueryCriteria which performs a boolean AND operation between multiple CriteriaElements?
You should be able to get what you want by using a 'dirty trick' with queries.
There is a way to put custom expressions in query ranges by using the DataArea field or the RecId field and putting in your expression.
Example:
query = new Query();
dsInventTable = query.addDataSource(tableNum(InventTable));
// Add our range
queryBuildRange = dsInventTable.addRange(fieldNum(InventTable, DataAreaId));
queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))',
fieldStr(InventTable, ItemType),
any2int(ItemType::Service),
any2int(ItemType::Item),
fieldStr(InventTable, ProjCategoryId),
queryValue("Spares")));
See the following link for more information : Expressions in query ranges

Order hql results by specific property value

I have a domain that contains a property called 'Status'.
This property can contain 'A','I','P','Pv','R'.
I have the following query:
def list = Deal.findAll('from Deal as d')
How can I order the results so that rows with status of 'P' are always returned at the top of the result set? (I don't care in what order they come after that).
Will this do what you want? Normally I'd test it before answering but I don't have an easy way to do that atm.
def list = Deal.findAll('''from Deal as d order by case d.property when 'P' then 0 else 1 end''')
You can use the sort method with a comparator:
def list = Deal.findAll('from Deal as d').sort({a,b-> (a.status== 'P' && b.status != 'P') ? 0 : 1 })

OData filter options (handle null or empty values)

We are using $filter system query option in OData to execute filters where the filter value is sent in at runtime.
As an example the OData URL would be like this:
http://services.odata.org/Northwind/Northwind.svc/Customers?$filter=CustomerID eq #InCustomerID and Country eq #InCountry
where #InCustomerID & #InCountry are the input values for the equal filter.
At run time when the user enters some value for Customer ID (say 'ABCD') we would replace the #InCustomerID by 'ABCD'
At runtime the query would be as follows:
http://services.odata.org/Northwind/Northwind.svc/Customers?$filter=CustomerID eq 'ABCD' and Country eq 'US'
In the above case the user has entered the following values: CustomerID => 'ABCD' and Country => 'US'
My question is regarding handling of null values in OData $filter. If the user does not enter any value for CustomerID then we want to select all customers from specific country.
In sql case this would be something like:
select * from Customers where ((CustomerID = #InCustomerID) or (#CustomerID is null)) and (Country = #Country).
Essentially how to handle null or empty values so that the specific predicate in the logical condition would always be true.
Does OData filtering enables this option?
You can compare to null using the equality operator like this:
$filter=CustomerID eq null
In your case the query would degenerate to something like:
$filter=(CustomerID eq null) or (null eq null)
Which should work, but it's not very nice.
Did you consider removing the predicate completely in such case?

Resources