Skip to content

Commit

Permalink
Merge branch 'fix/meme-staging' of github.com:valory-xyz/olas-operate…
Browse files Browse the repository at this point in the history
…-app into feature/modius
  • Loading branch information
Tanya-atatakai committed Dec 27, 2024
2 parents 14f8def + 3604787 commit b5b4b97
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 16 deletions.
16 changes: 9 additions & 7 deletions frontend/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ export type ChainData = {
};
};

export type EnvVariableAttributes = {
name: string;
description: string;
value: string;
provision_type: EnvProvisionType;
};

export type MiddlewareServiceResponse = {
service_config_id: string; // TODO: update with uuid once middleware integrated
name: string;
description: string;
hash: string;
hash_history: {
[block: string]: string;
Expand All @@ -63,13 +71,7 @@ export type MiddlewareServiceResponse = {
chain_data: ChainData;
};
};
};

export type EnvVariableAttributes = {
name: string;
description: string;
value: string;
provision_type: EnvProvisionType;
env_variables: { [key: string]: EnvVariableAttributes };
};

export type ServiceTemplate = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CHAIN_CONFIG } from '@/config/chains';
import { MechType } from '@/config/mechs';
import { STAKING_PROGRAMS } from '@/config/stakingPrograms';
import { SERVICE_TEMPLATES } from '@/constants/serviceTemplates';
import { AgentType } from '@/enums/Agent';
import { Pages } from '@/enums/Pages';
import { TokenSymbol } from '@/enums/Token';
import {
Expand Down Expand Up @@ -240,6 +241,25 @@ const useServiceDeployment = () => {
}
}

// Temporary: update the service if it has the default description
if (
service &&
service.description ===
SERVICE_TEMPLATES.find(
(template) => template.agentType === AgentType.Memeooorr,
)?.description
) {
const xUsername = service.env_variables?.TWIKIT_USERNAME?.value;
if (xUsername) {
await ServicesService.updateService({
serviceConfigId: service.service_config_id,
partialServiceTemplate: {
description: `Memeooorr @${xUsername}`,
},
});
}
}

// Start the service
try {
const serviceToStart = service ?? middlewareServiceResponse;
Expand Down
2 changes: 1 addition & 1 deletion frontend/constants/serviceTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const SERVICE_TEMPLATES: ServiceTemplate[] = [
{
agentType: AgentType.Memeooorr,
name: 'Memeooorr',
hash: 'bafybeigzqb77yjq2up5mzt72pj7vkq4xxhs2holy2susoicpyz6dz7ds4a',
hash: 'bafybeidkbylrtawgal322jsi7qvecbkk3havbvdsms7sabbeupabx2nhru',
description: 'Memeooorr @twitter_handle', // should be overwritten with twitter username
image:
'https://gateway.autonolas.tech/ipfs/QmQYDGMg8m91QQkTWSSmANs5tZwKrmvUCawXZfXVVWQPcu',
Expand Down
33 changes: 28 additions & 5 deletions operate/services/utils/memeooorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import asyncio
import json
import logging
import time
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -49,7 +50,12 @@ def await_for_cookies() -> dict:


async def async_get_twitter_cookies(
username: str, email: str, password: str, cookies: str, cookies_path: Path
username: str,
email: str,
password: str,
cookies: str,
cookies_path: Path,
max_retries: int = 10,
) -> Optional[str]:
"""Verifies that the Twitter credentials are correct and get the cookies"""

Expand All @@ -70,8 +76,8 @@ async def async_get_twitter_cookies(
if not valid_cookies and cookies_path.exists():
print("Checking the cookies file")
with open(cookies_path, "r", encoding="utf-8") as cookies_file:
cookies = json.load(cookies_file)
client.set_cookies(cookies)
cookies_json = json.load(cookies_file)
client.set_cookies(cookies_json)

user = await client.user()
print(f"User from cookies file: {user.screen_name}")
Expand All @@ -94,13 +100,30 @@ async def async_get_twitter_cookies(
# cookies = await_for_cookies() # noqa
# client.set_cookies(cookies) # noqa

except twikit.errors.NotFound as e:
logging.exception(e)
print("Error: Page not found. Sleeping for 10 seconds and retrying...")
await asyncio.sleep(10)
if max_retries == 0:
raise e
return await async_get_twitter_cookies(
username, email, password, cookies, cookies_path, max_retries - 1
)

return json.dumps(client.get_cookies()).replace(" ", "")


def get_twitter_cookies(
username: str, email: str, password: str, cookies: str, cookies_path: Path
username: str,
email: str,
password: str,
cookies: str,
cookies_path: Path,
max_retries: int = 10,
) -> Optional[str]:
"""get_twitter_cookies"""
return asyncio.run(
async_get_twitter_cookies(username, email, password, cookies, cookies_path)
async_get_twitter_cookies(
username, email, password, cookies, cookies_path, max_retries
)
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"start:frontend": "cd frontend && yarn start",
"test:frontend": "cd frontend && yarn test"
},
"version": "0.2.0-rc58",
"version": "0.2.0-rc62",
"engine": {
"node": ">=20",
"yarn": ">=1.22.0",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "olas-operate-middleware"
version = "0.2.0-rc58"
version = "0.2.0-rc62"
description = ""
authors = ["David Vilela <[email protected]>", "Viraj Patel <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion templates/memeooorr.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Memeooorr"
description: "Memeooorr @twitter_handle"
hash: bafybeigzqb77yjq2up5mzt72pj7vkq4xxhs2holy2susoicpyz6dz7ds4a
hash: bafybeidkbylrtawgal322jsi7qvecbkk3havbvdsms7sabbeupabx2nhru
image: https://gateway.autonolas.tech/ipfs/QmQYDGMg8m91QQkTWSSmANs5tZwKrmvUCawXZfXVVWQPcu
service_version: v0.2.0-alpha16
home_chain: "base"
Expand Down

0 comments on commit b5b4b97

Please sign in to comment.