Phos Phoenix Runtime Node
Root
defmodule R do
def recompile() do
Mix.Task.reenable("app.start")
Mix.Task.reenable("compile")
Mix.Task.reenable("compile.all")
compilers = Mix.compilers()
Enum.each(compilers, &Mix.Task.reenable("compile.#{&1}"))
Mix.Task.run("compile.all")
end
end
R.recompile()
External APIs
token = "secret_iEEKNgkL0gE0Havl8c840X0rSrUXlQf5xrKEXDzRqxb"
database = "6651c1b694844da39faa51d019fe6baf"
# headers = [
# Authorization: "Bearer #{token}",
# "Content-Type": "application/json",
# "Notion-Version": "2022-02-22"
# ]
today = DateTime.utc_now() |> DateTime.add(60 * 60 * 10) |> DateTime.to_date()
date_query = %{
"filter" => %{
"property" => "Posting date",
"date" => %{
"equals" => today
}
}
}
today_post = Phos.External.Notion.post!("/databases/" <> database <> "/query", date_query, [])
oRBs
Phos.Action.get_orbs_by_geohashes([614_269_017_680_510_975])
|> PhosWeb.Util.Viewer.fresh_orb_stream_mapper()
Users
user_id = List.first(Phos.Users.list_users()).id
{:ok, orb} =
Phos.Action.create_orb_and_publish(%{
"id" => Ecto.UUID.generate(),
"active" => true,
"extinguish" => ~N[2022-05-20 12:12:00],
"media" => true,
"title" => "weird",
"initiator_id" => user_id,
"geolocation" => [623_276_216_929_910_783],
"payload" => %{"where" => "here"}
})
orb
import Ecto.Query
alias Phos.Users.{RelationBranch, RelationRoot, User}
relation =
Phos.Folk.get_relation!("e9d5219f-76fe-4077-8a66-2e8fce6c6a2d")
|> Phos.Repo.preload([:last_memory])
# |> Phos.Users.RelationRoot.mutate_memory_changeset(%{
# "id" => Ecto.UUID.generate(),
# "message" => "really",
# "media" => "false",
# "user_source_id" => "6d7b0e7c-a633-4a8a-8d85-b8a493109bd4"
# })
# |> Phos.Repo.insert()
id = "6d7b0e7c-a633-4a8a-8d85-b8a493109bd4"
# Phos.Users.RelationBranch
# |> where([b], b.user_id == ^id)
# |> join(:inner, [b], r in assoc(b, :root))
# |> select([_b, r], r)
# |> join(:inner, [_b, r], m in assoc(r, :last_memory))
# |> join(:left, [_b, r, m], o in assoc(m, :orb_subject))
# |> select_merge([_b, r, m, o], %{last_memory: %{m | orb_subject: o}})
# |> order_by([_b, r, _m], desc: r.updated_at)
# |> Phos.Repo.all()
from(m in Phos.Users.RelationRoot, where: m.last_memory_id == ^relation.id)
|> Phos.Repo.all()
req = "5c82aeea-7c2b-4a97-a80b-d5b728c4ee86"
acpt = "9bf9c443-f89b-460a-972d-6704ae66823d"
alt = "deb2800c-a418-40fe-b35a-db30b01f59f8"
import Ecto.Query
alias Phos.Users.{RelationBranch, RelationRoot, User}
## CREATE
payload = %{
"initiator_id" => req,
"acceptor_id" => acpt,
"branches" => [
%{"user_id" => acpt, "friend_id" => req},
%{"user_id" => req, "friend_id" => acpt}
]
}
%RelationRoot{}
|> RelationRoot.gen_branches_changeset(payload)
|> Phos.Repo.insert()
# ## READ
# Phos.Repo.get_by(RelationBranch, [user_id: req, friend_id: acpt])
# |> Phos.Repo.preload(:root)
# ## UPDATE
# payloadz = %{"state" => "completed"}
# Phos.Repo.get!(RelationRoot, "5a096428-32b9-45a9-b5c1-a6f68443d201")
# |> RelationRoot.mutate_state_changeset(payloadz)
# |> Phos.Repo.update()
# doesnt't exist but has data msGW3TpSFQcmfqOmICkHZl1OImC2
# no data fFKlWcfV9RRavNZJUxt46BLYB5n1
Phos.Users.get_user_by_fyr("fFKlWcfV9RRavNZJUxt46BLYB5n1")
|> Phos.Repo.preload(:auths)
# Phos.Users.get_user_by_fyr("fFKlWcfV9RRavNZJUxt46BLYB5n1") |> Phos.Users.delete_user()
# PhosWeb.Util.Migrator.fyr_profile("eyJhbGciOiJSUzI1NiIsImtpZCI6IjVkMzQwZGRiYzNjNWJhY2M0Y2VlMWZiOWQxNmU5ODM3ZWM2MTYzZWIiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiVml2ZWtiYWxhIGZyb20gU2NyYXRjaGJhYyIsInBpY3R1cmUiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS9BTG01d3UxRkdhdm1hdm9VdXRxXzYwZ1VFdFlVbmpiNEh1UHZWRjRGdDN0WD1zOTYtYyIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9zY3JhdGNoYmFjLW5vcmJhbmR5IiwiYXVkIjoic2NyYXRjaGJhYy1ub3JiYW5keSIsImF1dGhfdGltZSI6MTY2NjUyNzQxOSwidXNlcl9pZCI6ImZGS2xXY2ZWOVJSYXZOWkpVeHQ0NkJMWUI1bjEiLCJzdWIiOiJmRktsV2NmVjlSUmF2TlpKVXh0NDZCTFlCNW4xIiwiaWF0IjoxNjY2NTI3NDE5LCJleHAiOjE2NjY1MzEwMTksImVtYWlsIjoidml2ZWtiYWxhQHNjcmF0Y2hiYWMuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZ29vZ2xlLmNvbSI6WyIxMDk1NDI1OTIzOTIwOTU0MzY4MjMiXSwiZW1haWwiOlsidml2ZWtiYWxhQHNjcmF0Y2hiYWMuY29tIl19LCJzaWduX2luX3Byb3ZpZGVyIjoiY3VzdG9tIn19.a5Zyy2CT0Im2gwCh9jnoKzaK58rq1A2memiO3jpsebQArQucozsyxPd4AhdBMOXTbiUvUgd_zAfDtmV-hzy_qhsYBmJNUjbbu2MYEHkd6RR66544isSPmb515-xaVV-BVbX2aeSpS8lspUTYXD0gVxPq58PqMkG4vvt-RHyv46FfATuUt02-SST7Xorp_6EpMoXmPwnsf6Q-7Q0ji0j0xWdrRpCSUfMfvJFmz6NEaWKd4LkXFdYB_6dzYtEv_C9KnIJYuBl1Bniwk5KHlbPvC20OT-gwD7fiyqJxU6XMoLjbDctwGM_vyESp6xiH9cnTEZgF4JFn50r_0Sk2o6evrw")
Notification
%{year: year, month: month, day: day} = Date.utc_today()
sgt = Timex.timezone("Asia/Singapore", {year, month, day})
DateTime.utc_now()
|> Timex.Timezone.convert(sgt)
|> DateTime.to_date()
Phos.External.Sector.get()
|> Map.take(["Bukit Panjang"])
|> Map.values()
|> List.flatten()
|> Phos.Action.notifiers_by_geohashes()
|> Enum.map(fn n -> Map.get(n, :fcm_token, nil) end)
# :h3.from_string('8d6520cb0811b7f')
Phos.External.Notion.platform_notification()
# Phos.Action.import_platform_notification()
orb = List.first(Phos.Action.list_orbs())
Phos.Folk.notifiers_by_friends(orb.initiator_id)
orb |>
#Phos.Action.notifiers_by_geohashes()
📸 Multimedia Support
Phos.Orbject.S3.get_all!("ORB", "5db9d048-f3b2-4d35-89cd-f242155d79db", "public/banner")
|> Enum.group_by(fn {path, _url} ->
String.split(path, ".")
|> List.first()
|> String.split("/")
|> List.last()
end)
🦇 Beacon
import Ecto.Query
alias Phos.Repo
hashes = [636_786_611_773_840_255 |> :h3.parent(8)]
from(l in Phos.Action.Orb_Location,
as: :l,
where: l.location_id in ^hashes,
left_join: orbs in assoc(l, :orbs),
inner_join: initiator in assoc(orbs, :initiator),
on: initiator.integrations["beacon"]["location"]["scope"] == true,
distinct: initiator.id,
select: initiator.integrations
)
|> Repo.all()
# |> Enum.map(fn n -> Map.get(n, :fcm_token, nil) end)
token =
"emrBcVu5TXy3BlK6wIigqW:APA91bHUaT1VQJmVAsZois0XpmOVAA60OOuJ9ZRG9tPOV3znabGCweo5-slZwYBh6CCaKycyiQUljbE5yBHONx9ZcGMvmNLoDbPsT0HCTV-oqg7b3iuUrU-nqyvhrNRkTbg4NZaPu6wg"
Phos.Users.get_user_by_username("deexupery")
|> Phos.Users.update_integrations_user(%{
"integrations" => %{
"fcm_token" => token
# "beacon" => %{"location" => %{"scope" => true, "subscribe" => [1, 2, "2", "4"]}}
}
})
# Phos.Users.get_user_by_username("lky")
defmodule DOMParser do
def extract_link_from_markdown(md) when is_binary(md) do
{:ok, ast, _} = EarmarkParser.as_ast(md)
String.trim(extract_link_from_ast(ast, ""))
end
defp extract_link_from_ast(ast, result) when is_list(ast) and is_binary(result) do
Enum.reduce_while(ast, result, fn
{"a", atts, children, _m}, acc ->
case Enum.into(atts, %{}) do
%{"href" => link} -> {:halt, link}
_ -> {:cont, extract_link_from_ast(children, acc)}
end
{_html_tag, _atts, children, _m}, acc ->
{:cont, extract_link_from_ast(children, acc)}
_, acc ->
{:cont, acc}
end)
end
end
DOMParser.extract_link_from_markdown("https://kosmonautx.github.io/")
|> LinkPreview.create()
𓅫 Sparrow
# comment =
# Phos.Comments.get_comment!("6f31a864-dc0c-41fa-a692-face2bec68d5")
# |> Phos.Repo.preload([:parent])
# Phos.PlatformNotification.notify({"broadcast", "COMMENT", comment.id, "replied_comment"},
# memory: %{
# user_source_id: comment.initiator_id,
# com_subject_id: comment.id,
# message: "#{comment.body}"
# },
# to: comment.parent.initiator_id,
# notification: %{
# title: "#{comment.initiator.username} replied",
# body: comment.body
# },
# data: %{
# action_path: "/comland/comments/children/#{comment.id}"
# }
# )
apple =
Sparrow.FCM.V1.APNS.new(
%Sparrow.APNS.Notification{
headers: [],
alert_opts: [],
aps_dictionary_opts: [],
custom_data: []
}
|> Sparrow.APNS.Notification.add_title("")
|> Sparrow.APNS.Notification.add_body("")
# |> Sparrow.APNS.Notification.add_apns_expiration("1682678925")
|> Sparrow.APNS.Notification.add_apns_priority("5")
|> Sparrow.APNS.Notification.add_badge(1)
# |> Sparrow.APNS.Notification.add_apns_collapse_id("owen")
|> Sparrow.APNS.Notification.add_content_available(1),
# |> Sparrow.APNS.Notification.add_mutable_content()
# |> Sparrow.APNS.Notification.add_thread_id("wow")
fn -> {"authorization", ""} end
)
token =
"emrBcVu5TXy3BlK6wIigqW:APA91bHUaT1VQJmVAsZois0XpmOVAA60OOuJ9ZRG9tPOV3znabGCweo5-slZwYBh6CCaKycyiQUljbE5yBHONx9ZcGMvmNLoDbPsT0HCTV-oqg7b3iuUrU-nqyvhrNRkTbg4NZaPu6wg"
title = "another1"
body = ""
data = %{}
[
Sparrow.FCM.V1.Notification.new(
:token,
token,
# [token] |> List.duplicate(2) |> List.flatten(),
title,
body,
data
)
|> Sparrow.FCM.V1.Notification.add_apns(apple)
]
|> List.duplicate(2)
|> List.flatten()
|> Sparrow.API.push()
[token]
|> List.duplicate(200)
|> List.flatten()
|> Enum.chunk_every(499)
🧭 Terra Firma
import Ecto.Query
hashes = [614_268_613_651_595_263, 614_268_617_290_153_983]
# seed hashes for sg or map into enum
locations =
Phos.Repo.all(
from(l in Phos.Action.Location,
where: l.id in ^hashes,
# join: message in assoc(l, :last_memory),
# select_merge: %{last_memory: message},
preload: [:last_memory],
select: {l.id, l}
)
)
|> Enum.into(%{})
Enum.reduce(hashes, %{}, fn hash, acc ->
Map.put(acc, hash, Map.get(locations, hash, %Phos.Action.Location{id: hash}))
end)
[
%Phos.Users.Geolocation{
id: "home",
location_description: nil,
geohash: 614_268_611_149_692_927,
chronolock: nil
}
]
|> Enum.find(fn l -> l.id == "home" end)
|> (& &1.geohash).()
🤖 Alberto Roboto
Phos.Action.telegram_chat_id_by_geohashes([614_268_985_654_902_783])
%{personal_orb: %{locations: loc}, private_profile: geo} =
Phos.Users.get_user_by_username("ggggggg")
|> Phos.Repo.preload(personal_orb: [:locations], private_profile: [])
loc |> Enum.map(& &1.id) |> Enum.map(&:h3.to_string(&1))
# geo
Phos.Action.get_orb!("5f631db9-d0fe-4488-8bc8-0a546e74a3e8")
|> Phos.Users.get_telegram_chat_ids_by_orb()