예제 #1
0
    def update_profile_photo(self,
                             client: TelegramClient,
                             file: BytesIO = None,
                             initial_photo_len: int = 0) -> None:
        try:
            pictures = client.get_profile_photos("me")
            if file:
                client(
                    UploadProfilePhotoRequest(file=client.upload_file(
                        file=file, file_name="cover.jpg")))
            if pictures.total > initial_photo_len:
                client(DeletePhotosRequest([pictures[0]]))

        except FloodWaitError as exception:
            LOGGER.INFO(
                f"UploadProfilePhotoRequest flood error pausing for {exception.seconds} seconds!"
            )
            time.sleep(exception.seconds)
예제 #2
0
def main():
    parser = ArgumentParser()
    set_arguments(parser)
    args = parser.parse_args()


    client = TelegramClient("tele_session", args.api_id, args.api_hash)
    client.start()

    prev_update_time = ""

    while True:
        if time_has_changed(prev_update_time):
            generate_and_save_quote()
            prev_update_time = convert_time_to_string(datetime.now())
            # client(DeletePhotosRequest(client.get_profile_photos('me')))
            client(DeletePhotosRequest(client.get_profile_photos('me', limit=1)))
            path_to_file = os.getcwd() + f"/src/quote_images/new_quote.jpg"
            file = client.upload_file(path_to_file)
            client(UploadProfilePhotoRequest(file))
        time.sleep(1)
예제 #3
0
class Tg:
    def __init__(self, session_name='CatPick'):
        self.client = TelegramClient(session_name, config.API_ID, config.API_HASH)
        self.client.connect()

    def get_last_photo(self):  # 1921618168832436147
        result = self.client(functions.photos.GetUserPhotosRequest(
            user_id='platun0v',
            offset=0,
            max_id=0,
            limit=100
        )).photos[0]
        logger.info(result)
        return result

    def delete_old_photo(self):
        photo = self.get_last_photo()
        result = self.client(functions.photos.DeletePhotosRequest(id=[photo]))
        logger.info(result)

    def upload_avatar(self, f_name: str):
        result = self.client(functions.photos.UploadProfilePhotoRequest(file=self.client.upload_file(f_name)))
        logger.info(result)
예제 #4
0
client.start()

prevNum = 0

while True:
    # clear current photo
    pics = client.get_profile_photos('me')

    if len(pics) != 0:
        pic = pics[0]

        client(
            DeletePhotosRequest(id=[
                InputPhoto(id=pic.id,
                           access_hash=pic.access_hash,
                           file_reference=pic.file_reference)
            ]))

    # get new random number
    newNum = random.randrange(1, 33)

    # prevent repetetive pics
    if newNum == prevNum:
        continue

    client(
        UploadProfilePhotoRequest(client.upload_file(f'./pics/{newNum}.jpg')))

    prevNum = newNum
    time.sleep(sleep_time + random.random())
예제 #5
0
# while n < numberOfPics:
#   pics = client.get_profile_photos('me')

#   p = pics[0]

#   client(DeletePhotosRequest(
#       id=[InputPhoto(
#           id=p.id,
#           access_hash=p.access_hash,
#           file_reference=p.file_reference
#       )]
#   ))

#   n += 1

# while numberOfPics >= 1:
#   try:
#     client(UploadProfilePhotoRequest(
#       client.upload_file(f'./pics/{numberOfPics}.png')
#     ))

#     time.sleep(1)
#     numberOfPics -= 1
#   except Exception as e:
#     if type(e) == FloodWaitError:
#       print(f'sleeping for {e.seconds} seconds')
#       time.sleep(e.seconds)

client(UploadProfilePhotoRequest(client.upload_file(f'./p.jpg')))
예제 #6
0
 def upload_profile_photo(self, tele_client: TelegramClient) -> None:
     input_file = tele_client.upload_file(self.path)
     request = UploadProfilePhotoRequest(file=input_file)
     result = tele_client(request)
     self.file_data = FileData.from_result(result)
     return
예제 #7
0
    font = ImageFont.truetype(font='font.otf', size=235)
    wt, ht = draw.textsize(time, font=font)
    draw.text(((W - wt) / 1.9, (H - ht - 60) / 2),
              time,
              font=font,
              fill='#ffffff')

    font = ImageFont.truetype(font='font.otf', size=50)
    draw.text((W / 7, H / 4.6),
              f"Температура: {temp}°C",
              font=font,
              fill='#ffffff')

    font = ImageFont.truetype(font='font.otf', size=78)
    draw.text((W / 4, H / 1.6), date, font=font, fill='#ffffff')

    font = ImageFont.truetype(font='font.otf', size=50)
    draw.text((W / 2.4, H / 1.17), "NICK", font=font, fill='#ffffff')
    img.save('now.jpg')


while True:  # Delete/Upload image
    if not now_time == get_time():
        current_time = get_time()
        now_time = current_time
        get_image(current_time, get_date(), get_temp())
        image = client.upload_file('now.jpg')
        client(DeletePhotosRequest(client.get_profile_photos('me')))
        client(UploadProfilePhotoRequest(image))