I want to pull in a user's newsfeed after they have authenticated. I am using the Koala gem but if I call get_connection('me', 'feed') it only returns the last three posts on my wall. I want the last ~100 posts (or since post 1234567) that would show up on the user's home page.
You can get all posts during a certain time period using FQL. Here is an example that should get you started:
#feed = Koala::Facebook::API.new(current_user.token)
to = Time.now.to_i
yest = 1.day.ago.to_i
#feed.fql_query("SELECT post_id, actor_id, target_id, message, likes FROM stream WHERE source_id = me() AND created_time > #{yest} AND created_time < #{to} AND type = 80
AND strpos(attachment.href, "youtu") >= 0")
require 'koala'
#graph = Koala::Facebook::API.new("YOUR_ACCESS_TOKEN")
#graph.fql_query("SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id = me() AND created_time > START_TIME AND created_time < END_TIME LIMIT 10")
Code borrowed from here.
Related
I have a table named nrt_bal_sheet
date |company_name|amount_db|amount_cr|balance| nrt_acc
11/12/2021 MoneyGram 5000 0 5000 0046D
11/12/2021 MoneyGram 0 2000 7000 0046D
11/12/2021 MoneyGram 0 20000 20000 0046D
12/9/2021 Ria Money 0 15000 15000 0039D
12/11/2021 MoneyGram 10000 857300 857300 0046T
12/11/2021 MoneyGram 1000 85730 914318.61 0046T
12/12/2021 MoneyGram 1000 85730 1000048.61 0046T
I want to sum of amount_db and amount_cr and balance group by date, nrt_acc, company_name and for those nrt_acc that has last letter "T" only.
I need the following results
date |company_name | amount_db |amount_cr | balance | nrt_acc
12/11/2021 MoneyGram 11000 943030 932030.00 0046T
12/12/2021 MoneyGram 1000 85730 1016760.00 0046T
Here is the code I have already done.
nrtBalanceSheet = (
from n in db.nrt_bal_sheet
group n by new { n.date, n.nrt_acc, n.company_name } into g
orderby g.date
select new ValuePassModel
{
advice_issue_date = g.Key.date,
company_name = g.key.company_name,
company_code = g.key.nrt_acc,
debit = g.Sum(n => n.amount_db),
credit = g.Sum(n => n.amount_cr),
nrt_bal_sheet = g.Sum(n => n.balance)
}
).ToList();
but I got this error.
Error CS1061 'IGrouping<<anonymous type: DateTime date, string
nrt_acc, string company_name>, nrt_bal_sheet>' does not contain a
definition for 'date' and no extension method 'date' accepting a first
argument of type 'IGrouping<<anonymous type: DateTime date, string
nrt_acc, string company_name>, nrt_bal_sheet>' could be found (are you
missing a using directive or an assembly reference?)
Please help me correct my linq query brothers.
As someone already indicated your Linq provider is important in this discussion. I.e. I tried this with Linq to Object and it works just fine as you can see from my LinqPad output screenshot. One option you have is to get the data, then do a .ToList() which will load your data in memory, then proceed with the rest of he Linq query so it will execute as Linq to Object. The bad side is that it will pull all the data from the datastore in memory.
I'm using the following function from cbpro in order to buy some ETH. The dictionary returned is:
auth_client.buy(price='400', size = '0.00001', order_type = "market", product_id = currency)
{'message': 'Invalid price 400'}
Is the package broken or am I just being sutpid? Also tried in the form 400.00 but also not working.
The leaderboard shows the same username even if they are different users in case they have the same value.
I don't know how to solve it but when in the code I ask to resist a variable it gives me only 3 elements and not 4 even if 4 come out.
code:
#client.command(aliases = ["lb"])
async def leaderboard(ctx,x = 10):
leader_board = {}
total = []
for user in economy_system:
name = int(user)
total_amount = economy_system[user]["wallet"] + economy_system[user]["bank"]
leader_board[total_amount] = name
total.append(total_amount)
print(leader_board)
total = sorted(total,reverse=True)
embed = discord.Embed(
title = f"Top {x} Richest People",
description = "This is decided on the basis of raw money in the bank and wallet",
color = 0x003399
)
index = 1
for amt in total:
id_ = leader_board[amt]
member = client.get_user(id_)
name = member.name
print(name)
embed.add_field(
name = f"{index}. {name}",
value = f"{amt}",
inline = False
)
if index == x:
break
else:
index += 1
await ctx.send(embed=embed)
print resists this:
{100: 523967502665908227, 350: 554617490806800387, 1100: 350886488235311126}
Padre Mapper
Flore (Orsolinismo)
Aetna
Aetna
In theory there should also be 100: 488826524791734275 (i.e. my user id) but it doesn't find it.
Your problem comes from this line:
leader_board[total_amount] = name
If total_amount is already a key (eg. two users have the same amount of money), it will replace the previous value (which was a user ID) and replace it with another user ID. In this situation, if multiple users have the same amount of money, only one will be saved in leader_board.
Then, you have this line:
total.append(total_amount)
In this case, if two users have the same amount of money, you would just have two identical values, which is normal but, considering the problem above, this will create a shift.
Let's say you have ten users with two of them who have the same amount of money. leader_board will only contain 9 items whereas total will contain 10 values. That's the reason why you have two of the same name in your message.
To solve the problem:
#client.command(aliases = ["lb"])
async def leaderboard(ctx, x=10):
d = {user_id: info["wallet"] + info["bank"] for user_id, info in economy_system.items()}
leaderboard = {user_id: amount for user_id, amount in sorted(d.items(), key=lambda item: item[1], reverse=True)}
embed = discord.Embed(
title = f"Top {x} Richest People",
description = "This is decided on the basis of raw money in the bank and wallet",
color = 0x003399
)
for index, infos in enumerate(leaderboard.items()):
user_id, amount = infos
member = client.get_user(user_id)
embed.add_field(
name = f"{index}. {member.display_name}",
value = f"{amount}",
inline = False
)
await ctx.send(embed=embed)
If I guessed right and your dictionnary is organized like this, it should work:
economy_system = {
user_id: {"bank": x, "wallet": y}
}
I can't find how to write this query in rom-sql. Is it possible to add plain sql to where?
It looks for announcements which do not intersect with requests.
announcements.when and requests.when are tstzrange columns in postgres.
SELECT "announcements".* FROM "announcements" WHERE (
(SELECT COUNT(requests.id)
FROM requests
WHERE requests.id IN (1,2,3) AND
(TSTZRANGE(lower(requests.when) - INTERVAL '1 HOUR', upper(requests.when) + INTERVAL '1 HOUR', '()') &&
TSTZRANGE(lower(announcements.when)), upper(announcements.when), '()') AND
requests.user_id = 42
) = 0
)
Check out the 'Advance Postgres support' section of the docs, http://api.rom-rb.org/rom-sql/ROM/SQL/Postgres/Types looks like there is support TsTzRange range('tstzrange', range_read_type(:tstzrange))
I found a solution to my problem.
Not sure if it's the right way in rom-sql.
I'll accept better answer if any appear.
Until that, here's my solution - Sequel.lit
In my case I defined a method in Announcements relation:
def available(user_id)
request_ids = requests.by_user_id(user_id).confirmed.pluck(:id)
# +- 1 hour around request is not available
# last argument '()' means "do not include boundaries"
request_when = "TSTZRANGE(
lower(requests.when) - INTERVAL '1 HOUR',
upper(requests.when) + INTERVAL '1 HOUR',
'()'
)"
announcement_when = "TSTZRANGE(lower(announcements.when), upper(announcements.when), '()')"
where(Sequel.lit(
"(SELECT COUNT(requests.id)
FROM requests
WHERE requests.id IN (:request_ids) AND
#{request_when} && #{announcement_when} AND
requests.user_id = :user_id) = 0",
user_id: user_id, request_ids: request_ids
))
end
i am using Stripe. I would like to know how can calculate number of day prorated
I want display something like that
1 additional seat ($9/month each - prorated for 26 days)
in the api i don't see any item prorate_day
Bolo
subscription_proration_date what you are looking for? Then it will calculate it for you.
See more at https://stripe.com/docs/subscriptions/guide
The example of pro-rated subscription in ruby is as follows
# Set your secret key: remember to change this to your live secret key in production
# See your keys here https://dashboard.stripe.com/account/apikeys
Stripe.api_key = "sk_test_9OkpsFpKa1HDHaZa7e0BeGaO"
proration_date = Time.now.to_i
invoice = Stripe::Invoice.upcoming(:customer => "cus_3R1W8PG2DmsmM9", :subscription => "sub_3R3PlB2YlJe84a",
:subscription_plan => "premium_monthly", :subscription_proration_date => proration_date)
current_prorations = invoice.lines.data.select { |ii| ii.period.start == proration_date }
cost = 0
current_prorations.each do |p|
cost += p.amount
end
# Display the cost of these prorations invoice items to the end user,
# and actually do the update when they agree.
# To make sure that the proration is calculated the same as when it was previewed,
# you need to pass in the proration_date parameter
# later...
subscription = Stripe::Subscription.retrieve("sub_3R3PlB2YlJe84a")
subscription.plan = "premium_monthly"
subscription.proration_date = proration_date
subscription.save